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
}
}

