PrinterJob and Memory Leak

I have encounter a serious memory leak when printing in Java. When the following code is compiled into a 'jar' (1.4.x and 1.5.x) and run, the Print process consumes roughly 4 Mb and never gives it back. Does anybody have a solution for recovering the lost memory?

import java.awt.*;

import java.awt.print.*;

public class BasicPrint extends JComponent implements Printable {

public int print(Graphics g, PageFormat pf, int pageIndex) {

if (pageIndex > 0) {

return Printable.NO_SUCH_PAGE;

}

Graphics2D g2d = (Graphics2D)g;

g2d.translate(pf.getImageableX(), pf.getImageableY());

g2d.draw3DRect(20,50,100,50,true)

return Printable.PAGE_EXISTS;

}

public static void main(String[] args) {

PrinterJob pjob = PrinterJob.getPrinterJob();

PageFormat pf = pjob.defaultPage();

pjob.setPrintable(new BasicPrint(), pf);

try {

pjob.print();

} catch (PrinterException e) {

}

//// You will need to set up a break point after this to examine the consequences on

//// Memory

}

}

[1115 byte] By [rodneynagela] at [2007-10-1 21:18:29]
# 1
> Does anybody have a solution for recovering the lost memory?See my reply to this thread http://forum.java.sun.com/thread.jspa?threadID=653588The jvm does return memory to the os; when is dependent on some option settings.
ChuckBinga at 2007-7-13 3:14:34 > top of Java-index,Administration Tools,Sun Connection...
# 2
Hi Chuck,Thanks for your reply however your response is rather cyrptic. Could you give me a hint on how to change this setting. Is it something that can be set in the java code or is it a system thing?Apologises for my idioticy.
Rod_Nagela at 2007-7-13 3:14:34 > top of Java-index,Administration Tools,Sun Connection...
# 3
The setting is an option that's used on the java command, for instance:java -XX:MaxHeapFreeRatio=70 <yourClassName>See the results returned by the search on the option name: http://www.google.com/search?q=XX:MaxHeapFreeRatio
ChuckBinga at 2007-7-13 3:14:34 > top of Java-index,Administration Tools,Sun Connection...