I\'m currently testing my proof of concept prototype dealing with XML schema, and built around a very memory consuming external library for tree automata (for which I\'ve got th
I have quite a bit of positive experience with this trivial approach:
System.gc();
Thread.sleep(500);
System.gc();
One GC run is often not enough due to object finalization issues, where an object may be resurrected in finalization. Therefore additional memory is released in the second GC run.
Do note that this, as well as ony other, seemingly "smarter", approaches, are all heuristics and quite dependant on the exact version of JVM, including its GC configuration. But in many cases you will not be so much interested in generality: if it works right now and allows you to do your measurements, it is the way to go.