In my application I use a handler with multiple runnables. To call these runnables I loop postDelayed so they act as timers. I realized over time this generates a massive heap (10mb and continues to increase). So my question is what can i use instead of postDelayed that wont generate a massive heap of messages?
In my application I use a handler with multiple runnables. To call these runnables
Share
It’s unlikely that your runnables consumes so much memory. Each runnable instance should be cleared by GC after it is processed. If you are creating and posting runnables faster then they are executed you would get ANR because your UI thread wouldn’t be able to dispatch input events. If you create new runnables often it will cause GC to trigger more often but your heap shouldn’t grow.
It’s more likely that you have memory leaks in your app. You can use MAT to check what exactly consumes a lot of memory in java heap.