Out of memory problem

20 views
Skip to first unread message

progr...@gmail.com

unread,
Jul 19, 2013, 1:19:18 AM7/19/13
to android...@googlegroups.com
I have a problem that may or may not be related to android-binding.
But you may be able to help me do the right thing when using android-binding.

Previously, I was fetching only the first page of results and displaying it in an ArrayListObservable. (Before that it was just an adapter and a normal ListView). The first page of 50 results was no problem.

Each item in the list has a few strings and an image.

I changed the ArrayListObservable to allow an infinite list by doing this:

public final ArrayListObservable<MyThing> foo = new ArrayListObservable<MyThing>(MyThing.class) {
    @Override
    public void onLoad(int position) {
        super.onLoad(position);
        if (position >= Loaded - 1) {
            loadMoreThings();
        }
    };
};

Loaded keeps track of how many elements we have loaded into the ArrayListObservable so far.



Anyway, this works great. But after loading a few hundred or so the app will crash because it is out of memory.
This didn't happen before I moved to Android-Binding. But that may not be a problem with A-B. I may just be using it wrong.

The MyThing class has this:

Observable Image = new Observable(Drawable.class)
StringObservable blah
IntegerObservable blah
IntegerObservable blah

So maybe it is that I'm keeping all those Drawables around? Does A-B recycle the list item views correctly?


How can I deal with this out of memory issue?

Thanks!!

Andy Tsui

unread,
Jul 19, 2013, 9:13:37 PM7/19/13
to android...@googlegroups.com
Image is always a big issue in Android. Depending on how large is your image, the limit varies a lot. This limitation is not only on A-B, but any other Android app.

For me, I always use a "caching" strategy to load images (note: the problem is about memory, so even local image you need this). For example, I create a static class to handle the images, which includes:

private LinkedHashMap<Url, Drawable> images;

For the LinkedHashMap, I can limit how many it is storing, and once it is over, it will remove the item. But remember, upon removing the item, you need to release the drawable from the memory. 

Hope this help

Andy


--
You received this message because you are subscribed to the Google Groups "AndroidBinding" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbindin...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages