Suggesting Kindly That the Garbage Collector Run

This you can do. The garbage collector runs in a separate thread from the thread of execution, reclaiming space here and there when it finds objects that can no longer be referenced, or other unreachable code.

The garbage collector has been around the block. She's seen objects come and go, every day throughout the years. And she's not about to take any lip from some upstart crow telling her how to manage her memory.

To suggest that the garbage collector run, which does not guarantee that it runs, try tempting her with this:

System.gc();

Note that, like other methods in the System class, this is the effective equivalent of calling

Runtime.getRuntime().gc();

This means that the Java Virtual Machine ...

Get Java Garage now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.