Garbage Collection and ICS.. (memory leak?)

abner69

Member
Licensed User
Longtime User
I am currently having a memory leak issue (Im pretty sure its not B4A) when using the scrollview control. I am loading data via a db. After 8-10 reloads, the APP becomes very sluggish, causing the scrollview to be very choppy, and APP response to slow considerably.

(note, I am clearing out everything before reloading the data)

On Froyo y Gingerbread, ICS, I decreased the load time, and some of the choppiness by hiding it, loading it, and then showing it.

However, memory usage continued to climb each new load. So, I stumbled across using the reflector lib to inject a hint for garbage collection. This immediately took my APP from 51MB (at the height of the choppiness) back down to 23MB (this seems to be the normal value)! I thought my problems were solved! Well, they are partially - on Froyo y Gingerbread, I now have no problems!

But, on ICS, while my "leak" appears to be gone, the app still becomes really sluggish, to the point of hardly responding.

So, I'm wondering if GC is handled differently in ICS?

I am using the following to call the hint injector:

B4X:
   Dim GCollector As Reflector
   GCollector.RunStaticMethod("java.lang.System", "gc", Null, Null)

any help or ideas would be greatly appreciated.

...Pablo
 

abner69

Member
Licensed User
Longtime User
@Klaus, thanks for the response..

Actually, my code is based upon his example..only I added the routine to load from db, changing fonts, colors, txt size, and fixed the tables to allow for variable height...
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
So, I'm wondering if GC is handled differently in ICS?

Yes.

B4X:
   Dim GCollector As Reflector
   GCollector.RunStaticMethod("java.lang.System", "gc", Null, Null)

You should avoid using such a code. As many Google Engineers said on their blog: "The garbage collector does not prevent memory leaks." And calling it yourself for anything else than bitmaps under Android version < 3 will probably do nothing useful.

Here's a link to a very informative video made by a Google engineer.
 
Upvote 0

abner69

Member
Licensed User
Longtime User
Thanks @Informatix for the video link... I now understand much better how gc works - everyone should watch it :)

...Pablo
 
Upvote 0
Top