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

OutOfMemoryError sometimes #634

Open
RafaRuiz opened this issue May 29, 2014 · 7 comments
Open

OutOfMemoryError sometimes #634

RafaRuiz opened this issue May 29, 2014 · 7 comments
Labels

Comments

@RafaRuiz
Copy link

Hello.

I tried to use this image http://www.flunny.com/file/pic/photo/2014/04/9e29b40c4c73bd166ee2a76f1003773a.jpg (big size)

If the first thing I do is load that image, it's loaded my ImageLoader.

But if I navigate along the app (downloading more images), and after that I try to load it, it gives me an OutOfMemoryError.

05-29 12:13:58.528: E/ImageLoader(5041): null
05-29 12:13:58.528: E/ImageLoader(5041): java.lang.OutOfMemoryError
05-29 12:13:58.528: E/ImageLoader(5041):    at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
05-29 12:13:58.528: E/ImageLoader(5041):    at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:703)
05-29 12:13:58.528: E/ImageLoader(5041):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:679)
05-29 12:13:58.528: E/ImageLoader(5041):    at com.nostra13.universalimageloader.core.decode.BaseImageDecoder.decode(BaseImageDecoder.java:78)
05-29 12:13:58.528: E/ImageLoader(5041):    at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.decodeImage(LoadAndDisplayImageTask.java:285)
05-29 12:13:58.528: E/ImageLoader(5041):    at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:231)
05-29 12:13:58.528: E/ImageLoader(5041):    at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:141)
05-29 12:13:58.528: E/ImageLoader(5041):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
05-29 12:13:58.528: E/ImageLoader(5041):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
05-29 12:13:58.528: E/ImageLoader(5041):    at java.lang.Thread.run(Thread.java:841)

How I load it:

                   HomeActivity.imageLoader.displayImage(item1.getThumb(), im1, HomeActivity.ILoptions, new ImageLoadingListener1(im1, pb1)); // Custom ImageLoadingListener which shows a ProgressBar

and my ILoptions and imageLoader are:

                    ILoptions = new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisc(true).build();
        imageLoader.init(ImageLoaderConfiguration.createDefault(HomeActivity.this));
@caseykulm
Copy link

There are suggested solutions on the homepage of this project under "Useful Info", for dealing specifically with Out Of Memory. My first suggestion would be to not enable cache in memory. Try that if that doesn't help read through the rest of the suggestions. If none of those work then you may have a leak in your app. A single copy of that image in memory is not too large.

@fefteroid
Copy link

hi .... i have an application i use grid view and the application is
offline but i have big problem with caching .. how can i avoid this problem

thanks

On Thu, May 29, 2014 at 5:40 PM, Casey Kulm notifications@github.comwrote:

There are suggested solutions on the homepage of this project under "Useful
Info"https://github.com/nostra13/Android-Universal-Image-Loader#useful-info,
for dealing specifically with Out Of Memory. My first suggestion would be
to not enable cache in memory. Try that if that doesn't help read through
the rest of the suggestions. If none of those work then you may have a leak
in your app. A single copy of that image in memory is not too large.


Reply to this email directly or view it on GitHubhttps://github.com//issues/634#issuecomment-44538898
.

@RafaRuiz
Copy link
Author

Thanks caseykulm,

but I need the memory in cache to load fast the thumbs on listview... should I define the max size of the thumbs?

Also what I want to know is why that happens

@caseykulm
Copy link

As stated before, the homepage has many suggested solutions aside from not caching in memory. It would definitely be beneficial to define the max size of the thumbnails, and there is a relevant StackOverflow post that Nostra himself answered.

Also to be able to know why this is happening you need to know what is in memory, and that can be done by digging through the heap dumps of your app with a memory profiler such as VisualVM.

If you have a memory leak somewhere in your app (likely holding Context somewhere) then it will permanently steal heap memory, and then by the time you try to load in this semi-large image, the heap will not be large enough, and you will get an OOM like you are seeing here.

@krunal09
Copy link

geting error like

E/ImageLoader(25118): null
E/ImageLoader(25118): java.lang.OutOfMemoryError
E/ImageLoader(25118): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
E/ImageLoader(25118): at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:620)
E/ImageLoader(25118): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)

@maysam
Copy link

maysam commented Mar 10, 2016

@nostra13 maybe you can use https://github.com/square/leakcanary in your sample app to see if there is a leak or not

@stevenchans
Copy link

please don use cacheInMemory if it is a listview you will find the memory increase fast

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants