Skip to content
Advertisement

Android Thread Allocation – growing heap?

Hi everyone out there,

i am developing an android application against API 7 at the moment in which i use an activity which need to be restarted. Lets say my activity looks like this:

JavaScript

The problem is that the gc doesnt seem to free the fullAnim thread so that the heap is growing by ~100K at every restart – till it slows down and crashes. Declaring fullAnim as static does solve this problem – but as i use non static references this doesnt work out for me.

So at this point i am kindof lost – and i hope u can advice me where to go next. Is there something i might be doing wrong or is there a tool i can use to manage threads to drop and free heap after restart.

kindly regards

UPDATE

thanks to everyone who answered – helped alot. using TimerTask did the trick in the end. i did the following change:

JavaScript

as the activity was more than 6k loc long this was a pretty decent solution without facing bigger impacts. KUDOS!

i dont use a Timer to shedule the task – dont know if its bad practice but the animation is called like this:

JavaScript

Advertisement

Answer

Because final variable have low priority for GC. So you need to explicitly release the runneable objects in onPause() method because there is not ensurence onDestory() will call immediate after finish() call .

JavaScript

UPDATE

use timer to achieve this

JavaScript
Advertisement