Reputation: 12656
I'm trying to improve performance of my Android app and I've concluded at least some of the problem lies with excessive garbage-collection. I can use heap tools to see what is getting allocated but it would nice to see what is getting garbage-collected.
Is there any way to tell what objects were freed in a Java GC? Is it possible with stock tools? Are there 3rd-party tools for this?
Upvotes: 2
Views: 83
Reputation: 52303
You can do this by capturing "before" and "after" heap dumps, and computing the difference.
The basic problem that makes this hard is that the GC doesn't decide what to discard, it decides what to keep, so it's not really geared toward gathering lists of freed objects. In some implementations there might not be per-object discard actions. (Imagine you have a table with a bit for every page of storage. At the start of the GC, set all bits to zero. For every object you keep, set the bit(s) on the page(s) it touches to 1. When you're done, any page with a zero bit is free and can be used for new allocations.)
You can play some games with finalizers and phantom references for the objects you create, but there's no equivalent for all heap objects.
Upvotes: 2