new BufferedImage OutOfMemoryError: Java heap space
I have client server program that the client send a screen captured image continuously to the server warping the BufferedImage to ImageIcon and then the client will read the ImageIcon and save it to a file via ImageIO.write using BufferedImage. Now the problem is for ever received image a new BufferedImage will be created in the while loop, after 6 fream there will be “OutOfMemoryError: Java heap space” error even if I increase the memory allocation for the project it wont work for more than 30 image.
Any help is appreciated.
Code snip where error occur
While(true){
ImageIcon imageIcon = (ImageIcon) objectInputStream.readObject();
//……
BufferedImage buffered = new BufferedImage(
imageIcon.getIconWidth(),
imageIcon.getIconHeight(),
BufferedImage.TYPE_INT_RGB
);
//……
}
On each loop a new BufferedImage will be created and I don’t think the previous is freed from memory? So is there a manual freeing method like C++? Or just let it crash ever 6 frame…