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

Out of Memory Error : Recycle? #20

Open
shaunidiot opened this issue Oct 4, 2012 · 9 comments
Open

Out of Memory Error : Recycle? #20

shaunidiot opened this issue Oct 4, 2012 · 9 comments

Comments

@shaunidiot
Copy link

Please forgive me for my noob-ness in Android programming. Just learnt Java weeks ago.

I've been using Lazylist to load images from website. However, I've been getting OOM error.
I searched it up on Stackoverflow and realized that recycle is needed so that space can be allocated for more images.
I looked it up on ImageLoader and this (recycle) wasn't implemented. I tried to code it myself yet faced with lots of error [bitmap.recycle()]. May I ask if this is possible?
Furthermore, in the listview, one image doesn't cause an error, yet when I add textview etc, it caused the OOM error too.
Thanks!

@thest1
Copy link
Owner

thest1 commented Oct 10, 2012

Sorry for a delay, too busy these days.
If you get OOM probably you do something wrong. Please check what's the
difference between your implementation and my sample.
Actually you should not call recycle because bitmaps are cache in memory.
If you don't cache them the scroll will be too slow. They're cache in
memory for some time and removed from memory when we don't need them. I use
this approach in many applications using a lot of bitmaps, work just fine.
OOM issues are very rare for me.

2012/10/4 shaunidiot notifications@github.com

Please forgive me for my noob-ness in Android programming. Just learnt
Java weeks ago.

I've been using Lazylist to load images from website. However, I've been
getting OOM error.
I searched it up on Stackoverflow and realized that recycle is needed so
that space can be allocated for more images.
I looked it up on ImageLoader and this (recycle) wasn't implemented. I
tried to code it myself yet faced with lots of error [bitmap.recycle()].
May I ask if this is possible?
Furthermore, in the listview, one image doesn't cause an error, yet when I
add textview etc, it caused the OOM error too.
Thanks!


Reply to this email directly or view it on GitHubhttps://github.com//issues/20.

@DeLL116
Copy link

DeLL116 commented Nov 29, 2012

I was having the same issues, specifically on the Motorola DroidX2 which has a 32mb heap limit AND is running Gingerbread......however....

I changed the Map instance of the cache object in the MemoryClass.java file to use a SoftReference to bitmaps like so:

private Map<String, SoftReference<Bitmap>> cache=Collections.synchronizedMap(
        new LinkedHashMap<String, SoftReference<Bitmap>>(10,1.5f,true));

Now I'm able to load up over 300 images all of great quality.

Obviously all calls to get() and put() needed to be modified to account for the change to SoftReference, but it's working great now.

I'm a noob, so if I'm dead wrong on this my apologies, but I thought I should let you know of my findings just in case it could help others.

Thank you for this library! It's awesome!

  • Chris

@thest1
Copy link
Owner

thest1 commented Nov 29, 2012

SoftReferences are not recommended to be used on Android. They may be cleared too fast and you'll get no cache at all, image will be parsed from SD each time. I had this problem before that's why I switched to my own MemoryCache implementation.

By default MemoryCache uses 25% of available memory. You can try to use less to have more free memory.

@asiri-07
Copy link

Dear thest1,
first, thanks for the awesome library. However, I am facing the same issues as DeLL116 and the first guy.
Could you pl ease re-check your approach for memory leakages with some heavy loading ?

@ankit662003
Copy link

hi @thest1 this is my app,it's work in progress and i am unsure if this is the way lazyload performs
please have a look at the app,it's only 1 mb
https://www.dropbox.com/s/anijtvbs4gp012t/PlayMee.apk

you will really like the app and i will mention your name on my company's website
i am 20 yrs old and I am a student ,so please help me out,I am not having errors but I think lazy load isn't performing to its potential...i tried saving memory by using weak references/soft references until i came across your answers,please help me out with this one.
I have used view holder pattern to increase the performance by not intializing the views again and again,it did help me to some extent but it did't solve the laggy scroll issue
I know you are busy and all but I think I really may need your help on this one as I am just 20yrs old and may need some guidance.
If you have decided to help me
here is the code you may need to look

https://www.dropbox.com/s/t7uoudwq30i58kx/LazyList.rar

I have a website under construction
www.playmee.org and i will mention your name there,if you would like
please help me out on this one,thanx

@thest1
Copy link
Owner

thest1 commented Mar 22, 2014

Laggy scroll usually means you're inflating new view in every getView() call or decode bitmap in every getVIew() call. Please investigate what exactly is happening when you scroll.

@vnju
Copy link

vnju commented Mar 25, 2014

Dear thest1
You're a cool man. Your project's really helpful for everyone. However, I also met a memory issue that
I used youtube user feed Project at https://github.com/coolbong/android-youtubeplayer, when i ran, it only shows around 30 images on listview. When i did ClearCache and pull to refresh, It can show more, but above images were disappeared
Could plz help me
Thanks alot

@vnju
Copy link

vnju commented Mar 25, 2014

I used SoftReference and everything's ok now. However, I want to get the solution from Thest1
thanks

@d7coders
Copy link

I have the same issue,
any solution ?

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

No branches or pull requests

7 participants