Printing causes gdi leakage?

Hi!
I have a problem when printing a lot of reports to the printer. I'm using java 1.5.0
running under Windows2003. I set up a nul printer (or pause my default printer)and run the
code below, and watch the gdi objects count (via Taskmanager) increase and increase and...
When it reaches 10000 the desktop will be messed up and my app stops printing.
How do I end a printerjob to avoid this????
Any help is appreciated,
Regards
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import javax.swing.JFrame;
* @author janne
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
public class PTest extends JFrame implements Printable
     class TestPrn extends Thread
          public boolean stop = false;
          private PTest frame;
          public TestPrn(PTest frame)
               this.frame = frame;
          public void stopMe()
               stop = true;
          public void run()
               while (!stop)
                    PrinterJob printerJob = PrinterJob.getPrinterJob();
                    printerJob.setPrintable(new PTest());
                    try
                         printerJob.print();
                    catch (Exception e)
                    try
                         Thread.sleep(1000);
                    catch (Exception e)
     private TestPrn pt;
     private javax.swing.JPanel jContentPane = null;
     private javax.swing.JButton jButton = null;
     static public PTest o = null;
     private javax.swing.JButton jButton1 = null;
      * This is the default constructor
     public PTest()
          super();
          initialize();
      * This method initializes this
      * @return void
     private void initialize()
          this.setSize(300, 200);
          this.setContentPane(getJContentPane());
          this.setTitle("PTest");
          this.addWindowListener(new java.awt.event.WindowAdapter()
               public void windowClosing(java.awt.event.WindowEvent e)
                    System.exit(0);
      * This method initializes jContentPane
      * @return javax.swing.JPanel
     private javax.swing.JPanel getJContentPane()
          if (jContentPane == null)
               jContentPane = new javax.swing.JPanel();
               jContentPane.setLayout(new java.awt.BorderLayout());
               jContentPane.add(getJButton(), java.awt.BorderLayout.SOUTH);
               jContentPane.add(getJButton1(), java.awt.BorderLayout.CENTER);
          return jContentPane;
      * This method initializes jButton
      * @return javax.swing.JButton
     private javax.swing.JButton getJButton()
          if (jButton == null)
               jButton = new javax.swing.JButton();
               jButton.setText("Start");
               jButton.addActionListener(new java.awt.event.ActionListener()
                    public void actionPerformed(java.awt.event.ActionEvent e)
                         pt = o.new TestPrn(o);
                         pt.start();
          return jButton;
     /* (non-Javadoc)
      * @see java.awt.print.Printable#print(java.awt.Graphics, java.awt.print.PageFormat, int)
     public int print(Graphics graphics, PageFormat format, int pageIndex) throws PrinterException
          System.out.println("In print");
          /* We'll assume that Jav2D is available.
          //          Graphics2D g2d = (Graphics2D) graphics;
          /* Move the origin from the corner of the Paper to the corner
           * of the imageable area.
          //          g2d.translate(format.getImageableX(), format.getImageableY());
          //          g2d.draw3DRect(10,10,100,500,true);
          //          return 0;
          graphics.dispose();
          return Printable.NO_SUCH_PAGE;
      * This method initializes jButton1
      * @return javax.swing.JButton
     private javax.swing.JButton getJButton1()
          if (jButton1 == null)
               jButton1 = new javax.swing.JButton();
               jButton1.setText("Stop");
               jButton1.addActionListener(new java.awt.event.ActionListener()
                    public void actionPerformed(java.awt.event.ActionEvent e)
                         if (pt != null)
                              pt.stopMe();
                              try
                                   Thread.sleep(1000);
                              catch (Exception ee)
                              pt = null;
          return jButton1;
public static void main(String[] args)
     o = new PTest();
     o.setVisible(true);
}

Hi,
I used to get serious GDI and memory leakage in my Swing apps.
If you "program like a C++ programmer" you won't get it....
ie.
1. explicitely remove components from containers when you're finished.
In fact I wrote a recursive function to start at a JFrame and recursively remove
all Swing components from it.
2. explicitely remove all listeners, actionlisterers, mouselisteners etc..
They hold references to your Swing components, and stop them from being
garbage collected. So, that nasty habit of yours to use anonymous classes
as actionlisteners must stop ! I prefer to let the class, in your case PTest,
implement the actionlisteners, and then just call addActionListener(this).
So, my guess is, it's not to do with the Printing as such.
regards,
Owen

Similar Messages

  • Printing causes Office 2013 applications to crash

    We’ve a fresh installed Windows 8 Pro and Office 2013. Printing works correctly in every application but Office 2013.
    Word, Excel, Outlook … printing causes the application to crash.
    Any idea if this is a known issue?
    Regards.
    Peter
    Peter Van Keymeulen, IT Infrastructure Solution Architect, www.edeconsulting.be

    This is the answer that fixes the problem every time, based on my experience and that of others. It works for both the 32 & 64-bit versions of Windows (I'm one of those odd ducks who runs 32-bit Windows 8.1 Professional and it worked perfectly for me).
    The problem is not Windows, either 7 or 8, it's Office 2013 and a variety of unique HP LaserJet printers.  By the way, the glitch occurs whether you use networked printing or a USB cable; I discovered that early-on when I
    was trying to troubleshoot the issue.  Also (and it should go without saying), always reboot the computer after you make the change to the driver.  Thanks to Shane, who apparently was the first one to discover the solution over a year ago, right
    after Office 2013 came out and the problem manifested itself.
    After lots of testing I have found a setting that has fixed all my HP CP5520 and HP M4555 printers that were crashing when printing from Office 365's 2013 pro plus.
    It's the driver setting in Device settings -> Installable options -> Printer Status notification, this needs to be disabled.
    I hope this also fixes other peoples problems.
    Shane

  • Printing causes macpro to crash/restart

    printing causes macpro to crash/restart

    OK, I understand borderless printing is not supported on plain paper, but I don't think a hard crash is an acceptable result.
    I can live with the minimize margins turned on but that opens up another documented bug where the last line to line and a half are not printed on the last sheet in a print set, If you are only printing one sheet at a time than every sheet will be missing this print. Has HP come up with or even looked into why this is happening?
    Thanks,
    Don

  • The action file print causes PS CS5 to hang, stop responding

    The action file print causes PS CS5 to hang, stop responding
    Its installed on a Win 7 64 bit PC i7 with 6G ram
    PS is version 12.0.4 64 bit
    The print dialouge box does come up eventualy around 10 mins later (some times).   While waiting PS is totaly dead and the task manager shows it as not responding
    Anyone got any ideas?

    I might suggest seeking out an updated printer driver to see if that will help.
    Is it possible you have a network path configured in there somewhere that's pointing to something no longer available on your network?
    -Noel

  • Did recent recommended update cause incompatibility with HP printer, causing error message and printer to print blank pages?

    did recent recommended update cause incompatibility with HP printer, causing error message and printer to print blank pages?

    Why not contact HP tech support for assistance since they make the printer. While on their site you can look for an updated printer driver. Otherwise, try deleting the current installed driver, reset the print system, then reinstall your printer's driver.
    Mac OS X- How to reset the printing system

  • Can Printer Cause Whirring Fan?

    Like many of you, I have had the whirring fan on my iMac. The other day, I disconnected my printer (HP psc 750) and I have noticed a dramatic reduction in the whirring noise while surfing the internet. Could the printer the problem or at least a part of it? What is a good printer for use with the iMac that won't cause this isse?

    Ok, my iMac G5 did have something similar to a "Whirring Fan" back when it was running 10.4.5, but right after I installed the 10.4.6 update, it seemed to be much better. I think that the printer honestly has nothing to do with the fans, but I could be wrong. What made you conclude that it was the printer causing the "Whirring Fan" other than when you unplugged it? (If you disconnected it and it was fine, then reconnected it and it was not, then it is the printer causing it to happen) Also, if you installed the 10.4.6 update and then disconnected the HP printer, then it was the update that fixed it.
    -Jason

  • B209a printer causes my internet to disconnect

    I have a photosmart plus all-in-one b209a printer. I down loaded the drivers and running through the wireless stetup, My computer connects wirelessly to the printer but is no longer connected to the internet. The only way I have been able to connect my computer wirelessly back up too the internet is to turn the printer off and restart the router? As long as my printer is on I can not connect too the internet...

    Make and model of router?  OS of computer?  Verify your router is on the latest firmware as this has caused issues like this in  the past.  Now try here.
    Printer does not maintain wireless connection.  
    http://h10025.www1.hp.com/ewfrf/wc/document?cc=us&lc=en&dlc=en&docname=c02790693#N74
    Say thanks by clicking the Kudos Thumbs Up to the right in the post.
    If my post resolved your problem, please mark it as an Accepted Solution ...
    I worked for HP but now I'm retired!

  • Printing causes Application Crashes

    Hi,
    I have a Macbook that I hook up to my Lexmark 5300 series printer via USB to print. The problem is that when I print (PDF or Document) it causes my application to crash. It does not even bring up the print option dialogue box. This includes Adobe Reader (Professional and Version 9), Preview, any Office program. I thought it might be the default PDF printer, so I deleted that. The only printer in the queue is the Lexmark. Is there anything else I should try?
    I am able to print from InDesign oddly enough, but it isn't a PDF it's a .indd format.
    Thank you!

    Updated drivers are a wonder.

  • Printing causes ALL apps to give "Not Responding " error

    After installing the recent round of Apple software updates ( iweb, pages, numbers, iphoto, etc) anytime I try to print from any application it causes the app to go into not responding mode..... the print diolog box never appears. If I force quit the app, restart it and then print everything is fine.... for awhile... then it starts all over again for each app.... any ideas?

    Your probably have a permissions problem. Open Disk Utility and run Repair Disk Permissions.
    If that doesn't help, open the Printer Setup Utility, click on the application menu and select Reset Printing System. Close Disk Utility and add your printer again. Note that you may have to run your driver installer again.

  • Right-click printing causes Explorer to crash?!

    We regularly print contact sheets by selecting a group of images, right-clicking and using the print wizard, but recently this has been causing Windows Explorer to crash. As many people use the laptop in question I can't be sure what recent updates have
    occurred that might have caused this.
    The error message was as follows:
    Problem signature:
      Problem Event Name:    APPCRASH
      Application Name:    Explorer.EXE
      Application Version:    6.1.7601.17567
      Application Timestamp:    4d672ee4
      Fault Module Name:    igdumd64.dll
      Fault Module Version:    8.15.10.2639
      Fault Module Timestamp:    4f29a5e5
      Exception Code:    c0000005
      Exception Offset:    000000000030e0b6
      OS Version:    6.1.7601.2.1.0.256.48
      Locale ID:    1033
      Additional Information 1:    2cb3
      Additional Information 2:    2cb33ab34750f572f12cbb253b809871
      Additional Information 3:    f019
      Additional Information 4:    f0199394a0f8932c6d2ba19d00fe529d
    Read our privacy statement online:
      http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409
    If the online privacy statement is not available, please read our privacy statement offline:
      C:\Windows\system32\en-US\erofflps.txt

    Hi,
    The log message here told this is caused by igdumd64.dll , which is a component of the Intel graphics driver:
    Faulting module name: igdumd64.dll, version: 8.15.10.2639.
    Please take a look at the PC's official Website for updated drivers.
    A similar thread for reference:
    Explorer crashes when right-click
    printing selected images as contact sheet
    Hope this may help
    Best regards
    Michael Shao
    TechNet Community Support

  • Javascript printing causes Adobe 9 to hang

    Hi,
    I have a J2EE App that fills out a form for the user, then opens the pdf and uses JavaScript to print the pdf.
    I have noticed that when I try and open the PDF(and javascript tries to print) AcroRd32.exe starts to use 100% CPU.
    It doesnt even print!
    Is anybody else running into this problem?
    Tristan

    I added the folder that my app downloads the PDF's to the priviliged folder list.
    This seems to clear up almost all of my issues.
    The one remaining issue is that if i try and open up multiple pdf's (all printing automatically) at the same time there are a certain few that will hang. It is always the same pdf's that will hang, and doesn't seem to matter how many working pdf's are opened before that one.
    ie if 1,2 work and 3 doesnt.
    opening each seperatley will work.
    opening 1 and 2 will work.
    oepning 1 and/or 2 then 3 will cause 1 and 2 to work while 3 hangs.
    If 1 or 2 is open then i open 3 it will hang.
    And just for fun this occurs in Windows XP SP2 but not Vista (rtm or sp1) It also does not occur in adobe reader 8.x in both xp and vista.
    Any ideas on what could cause this?

  • Landscape print causes images to be

    Hi.
    I am developing the printing portion of a Java-based medical imaging application. I need to be able to print a sheet containing several medical images (usually, grayscale images), with different layouts.
    I am using a code like this to start the print job:
    ===============================
    // Create the Print Job
    PrinterJob printJob = PrinterJob.getPrinterJob();
    // Create my own Printable Manager (implements the Printable interface)
    MyPrintableManager printMan = new MyPrintableManager();
    // Set the print attributes for initialization of print dialog
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(OrientationRequested.LANDSCAPE);
    aset.add(new Copies(1));
    aset.add(PrintQuality.HIGH);
    aset.add(new JobName("My Job Name", null));
    // Display the print dialog and start printing
    if (printJob.printDialog(aset))
    try
    // Set the Printable interface on the Print Job
    printJob.setPrintable(printMan);
    // Start the Print Job
    printJob.print(aset);
    catch (Exception ex)
    ex.printStackTrace();
    ===============================
    Then, in the class MyPrintableManager, I implemented my printing code in the print() method:
    ===============================
    public int print(Graphics g, PageFormat pf, int pi) throws PrinterException
    // Obtain a Graphics2D object for Java2D functionalities
    Graphics2D g2d = (Graphics2D)g;
    AffineTransform scaleTranslTransform = AffineTransform.getTranslateInstance(imgXOrigin, imgYOrigin);
    scaleTranslTransform.scale(finalScale, finalScale);
    BufferedImage bufImgToPrint = ...;
    g2d.drawRenderedImage(bufImgToPrint, scaleTranslTransform);
    ===============================
    I am facing the following strange behavior: if I choose the "Portrait" orientation in the Print dialog, everything is printed fine.
    On the other hand, when I choose the "Landscape" orientation in the Print dialog, grayscale images are printed "lighter" than what they shall be, as if something had increased the lightness of the grayscale image.
    Can you guess the cause for this strange behavior? Can it be a bug of the Java2D Printing API?
    Any help would be greatly appreciated.
    Regards,
    Marco.

    Should anyone be interested, I've assembled a self-contained code sample which demonstrates the problem with landscape printing of grayscale images (they get printed lighter than what they should be, while portrait printing looks fine):
    I've run the code below on Windows XP, JDK 1.5.0_06, and I am getting the problem with landscape printing: maybe some of you may want to make the test on his own PC and tell what happens...
    =====================================
    import java.awt.geom.*;
    import java.awt.print.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.io.*;
    import javax.imageio.*;
    import javax.print.attribute.standard.*;
    import javax.print.attribute.*;
    public class PrintableManager implements Printable
    private BufferedImage imgToPrint = null;
    public PrintableManager(BufferedImage img)
    imgToPrint = img;
    public int print(Graphics g, PageFormat pf, int pi) throws PrinterException
    if (pi >= 1)
    return Printable.NO_SUCH_PAGE;
    // Obtain a Graphics2D object for Java2D functionalities
    Graphics2D g2d = (Graphics2D)g;
    g2d.setClip(null);
    AffineTransform translTransform = AffineTransform.getTranslateInstance(pf.getImageableX(), pf.getImageableY());
    // Draw the final image
    g2d.drawRenderedImage(imgToPrint, translTransform);
    return Printable.PAGE_EXISTS;
    public static void main(String[] args)
    try
    // Substitute the path below with the actual path of the sample image
    // file on your hard drive (the used TestImg.jpg can be downloaded
    // from 'http://demo.neologica.it/Images/TestImg.jpg')
    File imgFile = new File("C:\\TestImg.jpg");
    BufferedImage imgToPrint = ImageIO.read(imgFile);
    // Create the Print Job
    PrinterJob printJob = PrinterJob.getPrinterJob();
    // Create the Printable Manager
    PrintableManager printMan = new PrintableManager(imgToPrint);
    // Set the print attributes for initialization of print dialog
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    // The following line is the crucial one:
    // If I specify OrientationRequested.LANDSCAPE, then the image is printed
    // LIGHTER (i.e., with a higher lightness) than what it should be.
    // If I specify OrientationRequested.PORTRAIT, then the image is printed
    // fine (i.e., with the correct lightness)
    aset.add(OrientationRequested.LANDSCAPE);
    // Display the print dialog and start printing
    if (printJob.printDialog(aset))
    // Set the Printable interface on the Print Job
    printJob.setPrintable(printMan);
    // Start the Print Job
    printJob.print(aset);
    catch (Exception ex)
    ex.printStackTrace();
    =====================================
    Thank you,
    Marco.

  • Printing causes crash

    I've just connectede an Epson photo 14000 onto my Mac (Leopard 10.5.8). Everytime i try to print an image using Photoshop CS2, Photoshop quits. Prints ok from PDF with Acrobat. any ideas? Thanks
    BB

    There was a known bug in one version of CS2 (9.0.1 if memory serves) that caused this under previous versions of the OS, but that was fixed in Photoshop 9.0.2.
    Make sure you have updated to Photoshop 9.0.2, and hope it works under Leopard.  Adobe does not support CS2 under Leopard, but with a little luck it might solve your problem.
    Wo Tai Lao Le
    我太老了

  • Sending Excel(.xls) to Adobe Pdf Printer causes a DDE Error

    Hi everybody!
    I have a problem with printing excel documents with Adobe Acrobat 7. Well actually its not me but a custommer of mine using a programm i have written. The programm starts a printing process for each document in a directory. This works fine for most of them. There are hundreds of xls files in this directory. There are only troubles with 3 or 4 of them. Every time i call one of this documents excel wants to open the xls file and print it over the default printer, in this case Adobe Pdf. But Excel is unable to open the file. The Error message only tells me that it seems to be a Problem with DDE and that i should check the length of the filename. Google told me that Excel is able to open files with a filenam up to 218 signs. The filenames of the files i try to print is only up to a 100 or max 150 signs( directory path included!).
    Is there anyone with an idea what may causes this problem. I need help. really.

    I think if the problem is with opening the file you may want to find a
    forum where Excel programming is discussed.
    Aandi Inston

  • Printer causes network to go down

    We have an HP Photosmart Premium C309g-m. We have three computers (all Dells, two XP boxes and one Win7) and that printer physically wired through a Linksys WRT54GX2 router. We do use the wireless for laptops, the Wii, and a Kindle, but we do not print wirelessly. Several days ago, and after no changes to anything that we were aware of, we discovered that turning on the printer killed any kind of network connectivity. The computers couldn't see each other, they couldn't see the printer, and they certainly couldn't see the internet. Turning off the printer solves the connectivity problems.
    I googled around on this and found some people who had similar problems trying to connect wirelessly, but we are wired. I tried cycling the router (disconnect from internet by pulling the cable, power off for 30 seconds, power back on, plug cable back in), but to no avail. Any assistance would be much appreciated.
    This question was solved.
    View Solution.

    I went to Linksys for a new firmware, and this is what I found:
    07/29/2011
    The firmware/driver for this product is no longer available for download. We regret any inconvenience this may cause you.
    So apparently I'm three months too late.
    FWIW, the printer does seem to be set up with a static IP. When I look at the printer properties in the control panel it lists a specific IP address.
    I'm stumped. Any other ideas would be greatly appreciated.
    Thanks all!

Maybe you are looking for

  • Problem Connecting iPad or iPhone to Wifi (Linksys E1000)

    I recently moved from my parent's house to a condo and I am having trouble connecting my iPad or iPhone to my WiFi.  I have not problem with my main desktop (connected to the router via ethernet), but my iPad and iPhone fails to connect to the networ

  • SQL Aggregate function and Subquery issues

    Hello, I'm trying to create an SQL statement that gives the rate of all Urgent surgeries Grouped by sector (i.e Surgery, Radiology), and Fiscal year To do this I need to divide the sum of surgeries with a state "Urgent" by the total surgeries In orde

  • DM selection issue

    Hi All, Currently I'm doing logic script allocation whereby the requirement in DM selection is to select any higher hierarchy level and the selection must pick up all descendents say level 3. To illustrate: Level 1 - PROD1      Level 2 - PROD2.1     

  • External context mapping issue: cannot create nodes,no mapping defined yet

    Hello everybody, I'm trying to use the external context mapping as it is explained in http://help.sap.com/saphelp_nw04/helpdata/en/d7/e551cf896c3a49bb87bb4ce38c99c8/frameset.htm I did it in the past without any problem, but now, when i try to create

  • Tabbing through cells of a JTable

    I have a JTable that has the following columns: Item, Desc, Qty1, Qty2, Qty3, Price The only fields that are editable are the Qty columns. Is there a way to make it so tabbing is only enabled to the Qty columns? For example, if the the cursor is in t