Skip to main content

JVM garbage collection

2 replies [Last post]
cohodetector
Offline
Joined: 2007-07-12

Hello,

I have a question about JVM garbage collection. I know that everytime i use the "new" operator it allocates the memory, so if i do it like this:

width = 1000;
height = 1000;
for(int i = 0; i < 1000; i++)
{
BufferedImage bi = new BufferedImage(1000,1000,BufferedImage.TYPE_INT_ARGB );
}

Will i get a out of memory problem? i mean will JVM allocates 1000 different memory location for "bi". or will JVM discard some of the "bi" that got created earlier when it is about to run out of memory.

Also, where is the JVM forum? i hope i put this message in the right place.

thanks

Francis

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
linuxhippy
Offline
Joined: 2004-01-07

Hi,

As soon as not enough free memory is left, the JVM will start a garbage collection, so your code won't lead to any memory leak.
The reason is that old BI's are not reachable anymore (you can't access the BI you've generated in a previous iteration anymore), so the GC simply removes them.

However large BIs are usually large, so you won't get best performance with that code of course ;)

lg Clemens

cohodetector
Offline
Joined: 2007-07-12

thank you so much for reply. It is very helpful. My actual image will be much smaller than this it is like 320 by 240 and i have 4gb of ram. by the way, what is the maximum heap and stack size java can handle. I use Eclipse IDE with windows xp. here is the Eclipse.ini file:

-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256M
-framework
plugins\org.eclipse.osgi_3.4.0.v20080605-1900.jar
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx256m

can i set it like this:

--launcher.XXMaxPermSize
1000M

-Xms512m
-Xmx2000m

i heard java max ram is at 1gb. is that true? If i allocate to the amount that is larger than java can handle, will i get a performance lost?

thank you

Francis Chan