Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): remove ImageDataHolder recycle #3787

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public class ImageDataHolder extends ImageRecycleObject implements ImageDataSupp
private Bitmap mBitmap;
@Nullable
private BitmapFactory.Options mOptions;
private final AtomicInteger mRefCount = new AtomicInteger(0);

public ImageDataHolder(@NonNull String source) {
init(source, null, 0, 0);
Expand Down Expand Up @@ -129,13 +128,12 @@ public void recycle() {

@Override
public void attached() {
mRefCount.incrementAndGet();

}

@Override
public void detached() {
mRefCount.decrementAndGet();
clear();

}

@Override
Expand All @@ -146,33 +144,6 @@ public void cached() {
@Override
public void evicted() {
resetStateFlag(FLAG_CACHED);
clear();
}

private void clear() {
if (mRefCount.get() > 0) {
return;
}
if (mDrawable instanceof Animatable && ((Animatable) mDrawable).isRunning()) {
((Animatable) mDrawable).stop();
}
if (checkStateFlag(FLAG_CACHED)) {
return;
}
if (mBitmap != null) {
if (checkStateFlag(FLAG_RECYCLABLE)) {
// If the bitmap is created locally, we need to manage its life cycle ourselves.
mBitmap.recycle();
}
mBitmap = null;
}
mGifMovie = null;
mDrawable = null;
mOptions = null;
mSource = null;
mKey = null;
mStateFlags = 0;
recycle();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,7 @@ private void handleResourceData(@NonNull String url, @NonNull final ImageDataKey
byte[] bytes = dataHolder.getBytes();
if (dataHolder.resultCode
== ResourceDataHolder.RESOURCE_LOAD_SUCCESS_CODE && bytes != null) {
imageHolder = ImageDataHolder.obtain();
if (imageHolder != null) {
imageHolder.init(url, urlKey, width, height);
} else {
imageHolder = new ImageDataHolder(url, urlKey, width, height);
}
imageHolder = new ImageDataHolder(url, urlKey, width, height);
try {
imageHolder.decodeImageData(bytes, initProps, mImageDecoderAdapter);
// Should check the request data returned from the host, if the data is
Expand Down
Loading