0

I make a treeview component by LinearLayout base. But when inner items count is very large android close it by out of memory error. I used only 3 bitmap by 3kb size in each items.

How can I reduce memory using of my component (LinearLayout) I know ListView has scrollingCache but I use LinearLayout ?
Can anyone help?
Thank you.

ali shekari
  • 740
  • 1
  • 11
  • 26

1 Answers1

0

The ListView use a system that initialize only the row(view) that are visible to the user. When a row in not visible anymore it doesn't get destroyed, but it is used to inflate the layout of the next view that will be visible. With this system you have to save in memory only for the object that are visible, even if there is 1000 of item in your list.

Here you can find a more accurate description of the recycle system

I think you should also take a look at this video. It's a lesson on ListView from Google I/O. I find out it is very useful to understand how ListView works .

In your case, if you cannot use ListView, i think you should implements manually this system. This is pretty hard so the best advice i can give you is to try to create a custom ListView that fit your needs and use it.

PS:The method recycle() is a bit different, it is used to delete any reference to the Bitmap on which you are using the method. This way, the next time the GC run, it will be able to delete from memory the Bitmap

Community
  • 1
  • 1
  • Try to take a look at the [ListView sourcecode](http://gitorious.org/android-eeepc/base/blobs/3661101005c6527dfd384d0c88c4a3b68ee208af/core/java/android/widget/ListView.java) and see if it help you. Without some of your code i can't do anything more :(. Hope it helps – Roberto Lombardini Aug 20 '13 at 08:45