views:

43

answers:

2

I have a java applet that loads up a scroll view that you can add several thousand views to, everything works fine. If I close that browser window and open a new window and view my applet again and start adding views it eventually runs out of memory. It seems like garbage collection didn't occur when I closed the window before:

a: why isn't memory freed once I close the window?

b: how can I make sure it is freed?

This is the latest version of java with FF and Safari.

A: 

Without seeing the code, my guess would be a reference to the window or one of it's components in your code which keeps it reachable.

Software Monkey
Unfortunately (or fortunately depending on how you look at it) I was accidentally keeping a strong reference to all the objects in question and I didn't notice because I thought it was commented out :p
Shizam
+2  A: 

It may be that the Java Browser Plugin can launch the applets in the same JVM. There is a applet parameter that you can use to launch your applet in a seperate JVM every time its launched in a new window:

<param name="separate_jvm" value="true">

Also you could leverage the start(), stop() and destroy() methods of you applet to clean up resources you are using.

There are some interesting facts about the java plugin. Check the forum. It has some important links

naikus
separate_jvm is an interesting param, for whatever reason though it's not launching a new jvm for me (even w/the latest Java). I put some code in stop() to remove stuff from the Swing GUI on exit but its still not GCing. It kind of bottles my mind that after I exit the application it keeps stuff in the VM's memory, makes no sense.
Shizam