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
Code :
//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?
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.