473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Applets not being garbage collected

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
Apr 19 '07 #1
2 4128
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).
>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.asp...neral/200704/1

Apr 19 '07 #2
Andrew Thompson wrote:
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 :-)
Browsers are nothing but trouble.
>
>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 :-)
Apr 19 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Scott Robinson | last post by:
I have been having trouble with the garbage collector and sockets. Unfortunately, google keeps telling me that the problem is the garbage collector ignoring dead (closed?) sockets instead of...
3
by: Bryan | last post by:
I've been messing around with a C++ application on Xbox, and have been encountering problems with my objects getting garbage collected when they go out of scope, but before I'm actually done using...
2
by: C P | last post by:
I'm coming from Delphi where I have to explicitly create and destroy instances of objects. I've been working through a C#/ASP.NET book, and many of the examples repeat the same SqlConnection,...
8
by: Martin Maat | last post by:
I am puzzled. I have this object that uses a thread. The thread is encapsulated by the object, the object has Start and Stop methods to enable the client to start or stop the thread. I found...
5
by: Razzie | last post by:
Hi all, A question from someone on a website got me thinking about this, and I wondered if anyone could explain this. A System.Threading.Timer object is garbage collected if it has no...
5
by: Ben | last post by:
Could someone please verify if what I am doing as follow is corrected: 1. when dealing with custom class objects: ..... public myObject as myClass myObject as New myClass .......here I am...
8
by: Paul.Lee.1971 | last post by:
Hi everyone, A program that I'm helping to code seems to slow down drastically during initialisation, and looking at the profiling graph, it seems to be the garbage collector thats slowing things...
6
by: massimo s. | last post by:
Hi, Python 2.4, Kubuntu 6.06. I'm no professional programmer (I am a ph.d. student in biophysics) but I have a fair knowledge of Python. I have a for loop that looks like the following : ...
56
by: Johnny E. Jensen | last post by:
Hellow I'am not sure what to think about the Garbage Collector. I have a Class OutlookObject, It have two private variables. Private Microsoft.Office.Interop.Outlook.Application _Application =...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.