PDA

Click to See Complete Forum and Search --> : [RESOLVED] Forcing a class to "die" ?


MalcolmCarmen
Jan 7th, 2006, 09:32 PM
Here's the problem - I have a plugin loading mechanism that dynamically loads classes like this:

- Define a variable as the class
- put the variable in an arraylist

The problem now is that when I attempt to unload such a plugin using .remove() with the arraylist, the class instance is still there. I noticed this when one of the plugins (a basic HTTPd) was still listening on a port when it should have been unloaded.

I've already tried using
System.runFinalization();
System.gc();

Thanks for any help!

ComputerJy
Jan 8th, 2006, 04:17 AM
This is one of two problems:-

1- There still is a dependancy using the object
2- The finalize() method in the class is manipulated so you can never erase the object while your program is still running

System_Error
Jan 8th, 2006, 07:27 AM
I've already tried using
System.runFinalization();
System.gc();



Rumors have it that you should call System.gc() twice. Have a go at it and see if it really works.

It is said that the first call marks the class loader and the second cleans it up. Not sure if it's true or if it will even work, but it's worth a try.


Oh, and I don't think you can unload something that's in use ;) See if you can stop it somehow first.

ComputerJy
Jan 8th, 2006, 06:39 PM
Rumors have it that you should call System.gc() twice. Have a go at it and see if it really works.

It is said that the first call marks the class loader and the second cleans it up. Not sure if it's true or if it will even work, but it's worth a try.


Oh, and I don't think you can unload something that's in use ;) See if you can stop it somehow first.

As far as I know, This problem was fixed in 1.4

System_Error
Jan 8th, 2006, 07:45 PM
I'm not sure of any details about it, or even if it's true. Would be nice to know if it's true, but if the classes are still running then it won't matter. He somehow needs to stop them from running.

MalcolmCarmen
Jan 9th, 2006, 08:16 PM
It appears my solution is to just load these classes as threads - not only does it speed up execution of my app, but it allows me to at least kill the instances easier. This app is large enough that tracking down object references left over would be a very unfun task!

ComputerJy
Jan 10th, 2006, 12:40 AM
It appears my solution is to just load these classes as threads - not only does it speed up execution of my app, but it allows me to at least kill the instances easier. This app is large enough that tracking down object references left over would be a very unfun task!
You didn't say your classes are already compiled and runnable.

CornedBee
Jan 12th, 2006, 05:37 AM
Killing threads is a bad idea.

Just create an interface that all these classes have to implement. Give it a method shutdown() that requires the plug-in to completely shut down all its activity.

ComputerJy
Jan 12th, 2006, 05:42 AM
Killing threads is a bad idea.

Just create an interface that all these classes have to implement. Give it a method shutdown() that requires the plug-in to completely shut down all its activity.
He didn't create the classes as I guess (Doesn't have the source)

MalcolmCarmen
Jan 16th, 2006, 02:00 PM
After playing with threads a lot, I've resigned to using CornedBee's suggestion - the classes is still instanced somewhere in the VM, but it isn't bothering me anymore!