We have a PHP webapp that calls a Java binary to produce a PDF report (with JasperReports). The Java binary outputs the PDF to standard output and exits; the PHP then sends
To avoid garbage collector release a variable or property from any object, you must set this property (released by gc) as static in your class it was my solution.
Example:
private static String myProperty;
GC only kicks in when JVM is short on memory, so you either GC or die. Try turning on verbose GC and see if it actually takes significant amount of time.
java -verbose:gc