Here\'s my use case. We are trying to narrow down a potential memory leak in an application, and we are using a memory analysis tool to snapshot the heap so we can look for obj
Calling GC should always release all weakly-reachable objects (assuming the "request" made by calling System.gc
is actually granted). If weak references are not getting cleared by GC, it means the objects are at least softly reachable.
Clearing soft references is trickier, as this is up to the JVM's discretion. The only way to guarantee clearing of softly-reachable objects is to cause an OutOfMemoryError
to be thrown. This trick is demonstrated in this discussion.