Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: OutOfMemoryError caused in a loop at new BufferedImage

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Red face OutOfMemoryError caused in a loop at new BufferedImage

    Have increase the memory size but that only increase the images send and received about x3, so the really solution is if there is a way to manually de allocate the memory without the gc or really force gc to do so…if that a no, could there be some modification that could FIX this???
    thanks

    //server
            int number=0;
                try {
     
                    while(true){
                         ImageIcon imageIcon = (ImageIcon) ObjectInputStream.readObject();
                         System.out.println("New image recieved");
                         BufferedImage bim =new BufferedImage(imgIcon.getIconWidth(), imgIcon.getIconHeight(), BufferedImage.TYPE_INT_RGB);
                         ImageIO.write(bim, "JPG", new File("image"+ number++ +".jpg");
    				Runtime runtime= Runtime.getRuntime();
    				runtime.gc();			//doesnt work
    		}
    	}cartch(IOException ex){
    //
    	}
     
    //client
    	screenDim=Toolkit.getDefaultToolkit().getScreenSize();
            scrRect=new Rectangle(screenDim);
     
            while(true){
                bufrdImage=robot.createScreenCapture(Toolkit.getDefaultToolkit().getScreenSize());
                imgIcon=new ImageIcon(bufrdImage);
     
                try {
                    client.oos.writeObject(imgIcon);
                    System.out.println("image Sent");
                } catch (Exception e) {
                }
                bufrdImage = null;
                imgIcon = null;
    				Runtime runtime= Runtime.getRuntime();
    				runtime.gc();		//to de allocate bufrdImage, imgIcon but doesnt work
                try{
                    Thread.sleep(1000);
                }catch(InterruptedException e){
                }
            }

    any idea?


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,099
    Thanks
    169
    Thanked 779 Times in 725 Posts
    Blog Entries
    5

    Default Re: OutOfMemoryError caused in a loop at new BufferedImage

    Which is throwing the exception, client or server (or both)? If you are getting an OutOfMemoryException I doubt its the garbage collectors fault.

Similar Threads

  1. Creating a bufferedimage!
    By Vexst in forum Java ME (Mobile Edition)
    Replies: 0
    Last Post: June 16th, 2010, 08:05 AM
  2. Replies: 15
    Last Post: February 28th, 2010, 09:30 PM
  3. free memory of bufferedimage
    By mr_empty in forum Java SE APIs
    Replies: 2
    Last Post: January 19th, 2010, 05:14 AM
  4. OutOfMemoryError (Java heap space)
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 21st, 2009, 10:56 AM
  5. Replies: 2
    Last Post: June 29th, 2009, 03:06 PM