> I am having problems reclaiming memory consumed by a > (supposedly > GC'ed) BufferedImage. When I want to dispose of an > image, I basically > do: >
That's because in Java you never explicitly reclaim memory. > img.flush(); > img = null; > Nice, but rather pointless. > I was expecting this to free the memory from all Wrong expectations. > resources associated > with this BufferedImage. Unfortunately it does not > seem to be the As you should know if you'd known a bit more about the Java memory model and programming paradigm. > case. After some time I get a > java.lang.OutOfMemoryError: Java heap Could happen. > space. Manual calls to System.gc() do not change > anything to the Of course not. As you would know if you knew more about Java memory management. > current memory consumption. I ran tests with a pretty > big heap size (- which only delays the inevitable > Xmx1024M). I monitored the memory consumption using > Runtime.getRuntime > ().totalMemory() and > Runtime.getRuntime().freeMemory(). > > Am I missing something? > yes, you're hanging on to references to that BufferedImage somewhere, preventing it from being garbage collected. So you're getting rid of some references to that image, but never the image itself. Did you put it in a Collection somewhere, maybe? > BufferedImage constructor. I noticed it while writing > a simple > slideshow application which I tested with pretty big > images So you're creating a List of BufferedImage instances for later display? If so, there's the problem. Each image is using several megabytes of memory and you're hanging on to all of them. Sooner or later you're bound to run out. > BufferedImage, which is not GC'ed when I "kill" it as > described above. > You don't "kill" anything. You only null a reference, but apparently not all of them. [Message sent by forum member 'jwenting' (jwenting)] http://forums.java.net/jive/thread.jspa?messageID=246758 =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA2D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".