Skip to content

Commit

Permalink
fix(android): remove ImageDataHolder recycle
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 committed Mar 21, 2024
1 parent 9a76f96 commit 6363392
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 37 deletions.
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

0 comments on commit 6363392

Please sign in to comment.