Discussion Locked

JApplet Memory Leakage/GarbageCollection

0 helpful
12 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

We have a JApplet and it loads several JApplets in other frames on click of menu items. These new JApplets are destroyed when new menu items are clicked and then these Japplets are again called with another set of data. We found that the memory usage continuously went up and the memory occupied by the objects of the destroyed JApplets apparently did not get released or garbage collected. As a result, soon we ran out of memory.

We have tried the following without any positive results:

1. We have explicitly set all Objects held by the called JApplets to 'null' in destroy() method.

2. We have explicitly called Runtime.gc() (to call garbage collector to free the memory) and dealloc()).

3. We have looked into our code and confirmedthat there were no circular references to the objects.

Any solution?

12 replies

by timthetoolman

Hi,

Not much of an answer, I know... but you must still have a reference to the object somewhere.

I would have thought that you needed to set the references TO the objects to null... not the objects themselves...

Cheers,
Tim.

by drprabhu

We have already tried this but with no success. Thanks anyway for taking time to answer. If you get more ideas please do let me know. Thanks....Dinesh

by shanghai sam

1. u don't run the garbage collector, wenn u call Runtime.gc() - u only suggest the system to do so.
2. the destroy()-method is called by the browser plugin, when u exit the site. u could type System.out.println("destroy"); in the method, to determine, when it is called.
3. the destroy()-method is called, wenn the Applet is being garbage collected: so it doesn't matter, if u set all object references to null.

i hope that helps, to determine the problem.

p.s. did u try it in netscape or ie?

by drprabhu

Thank you for your prompt response. What you have suggested is helpful in explaining the problem & why we were not successful with our efforts but we still do not have a solution. We still need to know how to get around this problem. You are most welcome to give more ideas, if any. FYI, we used I.E. Thanks once again...Dinesh

by shanghai sam

1. u don't run the garbage collector, wenn u call Runtime.gc() - u only suggest the system to do so.
2. the destroy()-method is called by the browser plugin, when u exit the site. u could type System.out.println("destroy"); in the method, to determine, when it is called.
3. the destroy()-method is called, wenn the Applet is being garbage collected: so it doesn't matter, if u set all object references to null.

i hope that helps, to determine the problem.

p.s. did u try it in netscape or ie?

by drprabhu

Thank you for your prompt response. What you have suggested is helpful in explaining the problem & why we were not successful with our efforts but we still do not have a solution. You are most welcome to give more ideas, if any. FYI, we used I.E. Thanks once again...Dinesh

by timthetoolman

Hi,

I haven't really gone into the java debuggers yet... but can you run in debug mode and look to see what all the variables are set to during the run? Particularly the ones that refer to the objects that you wish to have cleaned up.

I believe that once you've gone passed the point when the references to those objects have been set to null, then they wont even show up in the debugger anymore.

If they do... then check all references to find where/why.

Just a thought.

Cheers,
Tim.

by timthetoolman

Hi,

So you'd be seeing multiple objects being created (hundreds or even thousands of them by the sound of it since you're running out of memory)

But none being destroyed?

Or do they appear gone but memory usage is still climbing?

The best way to ensure the objects CAB be cleaned up is to have them go out of scope. Then there can be no way they are referred to by anything else. Try re-arranging your code...

Cheers,
Tim.

by drprabhu

We at last located the memory leak which was happening in the third party component that we were using. Thanks for taking time and efforts to give suggestions and therefore, you deserve the points....Dinesh

This discussion is closed to new replies.