AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Applets not being garbage collected

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> comp.lang.java
View previous topic :: View next topic  
Author Message
Robert Larsen
Guest





PostPosted: Thu Apr 19, 2007 5:35 pm    Post subject: Applets not being garbage collected Reply with quote



Hi

I am developing Java applet games and have come across a problem that
seems to exist in the VM from Sun. I have tested in Mozilla and Firefox
on Windows and Linux and IE (several versions) on Windows.

When I run a game applet and then reload the page, two instances of the
game are running in the same VM. I have verified this with JMP
(http://www.khelekore.org/jmp/), and as the more recent games use lots
of memory (up to 42 megs), they run out of memory and throws a:

Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java
heap space
java.lang.OutOfMemoryError: Java heap space

If not on the first reload then on the second or third. This also
happens if I close down the window and open the game again. The only
thing that works is closing down all windows.

I have the following in the applets destroy() method:

public void destroy() {
System.out.println("Applet destroyed");
applet = null;
appletAdapter = null;

if (engine != null) {
engine.destroy();
engine = null;
}
System.gc();
}

'applet' is a reference to the applet itself.
'appletAdapter' is a proxy for calling methods on the applet (games can
also run as an application so this object implements methods for getting
"host", "applet parameters" and calling JavaScript without the need for
an actual applet).
The engine object is the actual game and the applet does not have any
other references to anything, so this should clean up everything.
I also have this in the applet:

public void finalize() {
super.finalize();
System.out.println("Applet finalized");
}
....and this in the game engine:
protected void finalize() throws Throwable{
super.finalize();
System.out.println ("Engine finalized");
}


When I refresh the page I get "Applet destroyed" in my console but
neither "Applet finalized" nor "Engine finalized" + I can see in JMP
that there are two instances of both the GameEngine (the 'engine'
reference) object and the applet.

One (obj. id.: 0x8b384ae0) is owned by sun.plugin.AppletViewer (obj.
id.: 0x8b382e40) which is owned by
sun.plugin.viewer.MNetscapePluginObject (obj. id.: 0x8b382a70) which is
owned by sun.plugin.AppletViewer (obj. id.: 0x8b382e40).

The other (obj. id.: 0x88f33000) is owned by java.lang.ref.Finalizer
(obj. id.: 0x88f33118).
And it seems that it is never actually finalized. I hit the System.gc
button in JMP and it frees lots of stuff, but not the applet and not the
game engine. I have had it running for hours and the finalizer never
seem to free the old reference.

I have tried inserting a delay for one minute before instanciating the
game engine so the garbage collecter has lots of time to free something
but that didn't help.


Do you guys know why this is ?
Can anything be done about it ?

Best regards,
Robert
Back to top
Andrew Thompson
Guest





PostPosted: Thu Apr 19, 2007 6:01 pm    Post subject: Re: Applets not being garbage collected Reply with quote



Robert Larsen wrote:
..
(applet browser memory problem)
Quote:
Do you guys know why this is ?

No (and I personally, am beyond caring about
applet/browser/VM interaction problems).

Quote:
Can anything be done about it ?

Launch the applet using web start. Here is an
example of an applet launched using web start.
<http://www.physci.org/jws/#jtest>

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200704/1
Back to top
Robert Larsen
Guest





PostPosted: Thu Apr 19, 2007 6:40 pm    Post subject: Re: Applets not being garbage collected Reply with quote



Andrew Thompson wrote:
Quote:
Robert Larsen wrote:
.
(applet browser memory problem)
Do you guys know why this is ?

No (and I personally, am beyond caring about
applet/browser/VM interaction problems).

Oh how I wish I lived in your world Smile
Browsers are nothing but trouble.

Quote:

Can anything be done about it ?

Launch the applet using web start. Here is an
example of an applet launched using web start.
http://www.physci.org/jws/#jtest


This has crossed my mind. Problem is that actually two applets run on
the same page (a game and a chat applet) and running two separate
windows would...well...suck.
This may be the path I take if no other solution is found, but then I
will build a new application with both the game and the chat in one. But
I would really like to avoid that extra work so if anybody else has a
solution I would dance a happy dance and buy you a beer Smile
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> comp.lang.java All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.