Skip to main content

free memory of bufferedimage

1 reply [Last post]
mr_empty
Offline
Joined: 2008-02-28

hi all,

i have the following code.

BufferedImage img=new BufferedImage(29342,450,BufferedImage.TYPE_INT_RGB);

Graphics2D g2d=img.createGraphics();
g2d.drawImage(r.getAsBufferedImage(), 0, 0, null);
g2d.finalize();
g2d.dispose();

img.flush();
img=null;

but i cannot free img object all uts memory since i know there is the reference to it, but for this problem how to solve it? thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
fred34
Offline
Joined: 2004-06-19

Hi,

Remove the g2d.finalize() call, its unnecessary and serves no purpose here. The GC will automatically remove the BufferedImage from memory once there are no references to it. If it isn't being freed then check your program to make sure a reference hasn't escaped somewhere. The flush() call is only necessary to remove and cached copy in VRAM.