-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Possible Memory Waste (OutOfMemoryError) with Solution #475
Comments
I fixed your source code in this way: public class ImageNonViewAware implements ImageAware {
protected final String uri;
protected final ImageSize imageSize;
protected final ViewScaleType scaleType;
public ImageNonViewAware(String uri, ImageSize imageSize, ViewScaleType scaleType) {
this.uri = uri;
this.imageSize = imageSize;
this.scaleType = scaleType;
}
@Override
public int getId() {
return TextUtils.isEmpty(uri) ? super.hashCode() : uri.hashCode();
}
} public class ImageLoader {
public void loadImage(String uri, ImageSize targetImageSize, DisplayImageOptions options,
ImageLoadingListener listener) {
checkConfiguration();
if (targetImageSize == null) {
targetImageSize = configuration.getMaxImageSize();
}
if (options == null) {
options = configuration.defaultDisplayImageOptions;
}
ImageNonViewAware imageAware = new ImageNonViewAware(uri, targetImageSize, ViewScaleType.CROP);
displayImage(uri, imageAware, options, listener);
}
} Now there is no waste of resource and this library is great. No more OutOfMemoryError |
I got your fix. Actually I thought about exactly the same version of You have a very special usage of ImageLoader, you call |
I use in this way because I need to use the last recents cached bitmaps if exist in memory cache or disc cache, else load and cache image (i do some long operation on the image the first time before cache) I arrived at this solution because I noticed that if I load an image with an uri, the uri is unique to the image and will be unique even then the hashCode. So there is no need to cancel previous loading task.
Instead, when I use the method displayImage, the ImageViewAware works well because it uses imageView.hashCode as id. PS: my app is a game with animations and these are the results after the fix: |
Yes, I understand. You should use |
Hi,
I am using this library since 3 days and using the dump profile of eclipse I found that if application uses ImageLoader in a SurfaceView, there could be a Possible Memory Waste
This is the dump in my app:
The real problem is in com.nostra13.universalimageloader.core.ImageLoaderEngine and exactly in:
Step to reproduce:
The text was updated successfully, but these errors were encountered: