Post 5.0 (Tiger): offer 'force free object references'
Possible memory leaks in Java applications can easily occur, if the object that is released to the garbage collector (no reference to this object from the application) still access static resources. There is currently no way to tell the VM to free these resources also (because they are static and still might be requested somewhere). However, the developer should have the option to tell the VM to free ALL resources tha an object holds.
Example is that a class uses some 3rd party libs that hold internal static references and therefore lead to memory leaks. The developer should be able to do somethign like
Object myObject =new SomeClass();
myObject.calculate();
//now, i don't need the object anymore and want to get rid of it:
myObject =null;//only way so far
SomeClass.releaseResources();//something like that
SomeClass.finalize();//should have default implementation to release static resources
Your assumption that there is no way to free statically held resourses is not correct. When the classloader of an object is released and GC'ed all statically held resources will be released at the same time.Dave.
How can a cloassloader be released? And does this only work for custom classloaders? If yes, an object can't be instantiaded via the standard "new", but a separet class loader have to be written and used. This sounds like quite some heavy overload ...
> How can a cloassloader be released?
In exactly the same way as any other object.
> And does this only
> work for custom classloaders?
This only works for classloaders other than the system default classloader because you don't hold a reference to that one. I think that was what you meant, but that itsn't what "custom classloaders" actually means (a custom classloader is one you implement yourself to solve some problem, rather than a library available one like, say, URLClassloader).
> [...]an object can't
> be instantiaded via the standard "new", but a separet
> class loader have to be written and used. This sounds
> like quite some heavy overload ...
You mean compared to a language extension that can't work as described ?
Call me harsh, but I think knowing how the language actually works is a pre-requisite for people making proposals to extend it.
Dave.
Well, but if it's already possible via writing your own classloader and freeing this classLoader object, this is a much worse way to workaround this now than to just have a nice method telling the class to unload itself (from the default classLoader). This would avoid much hassle (and errors) compared to fiddle around with custom class loaders.
You don't understand. You can free the objects referenced by a classloader (by freeing the classloader) because you know that it is self contained. By definition. You can't just zap one of them and hope that everything will hang together.
Which is what you're proposing.
I understand the implications of what you're askiing for, and you don't. To prove me wrong, implement it. Your chances of getting this into a post-tiger release are zero, nada, zit, swabo, nothing. Unless you, personally, implement a proof-of-concept that a JSR can be based upon.
Dave.
Oh sorry, my master. I apologise for my little puny brain and bow in front of your light ...
Well what do you expect ? "Oh master what a brilliant idea, we shall implement it for you forthwith" ?
You obviously have no idea what you're asking for, so why the hell do you think you're competent to make the request ?
We should have an infinite capacity hard disk, no we should have code that does what you mean not what you say, no wait, I have a better idea, you should be able to write code by thinking hard at the computer. In your case that will probably give it epilepsy.
Why don't you spend some time first learning what the language can already do, what's impossible, and what's ruled out for reasons of taste and decency ? There's room for improvement, but (guess what) people prepared to do some work are already on the case.
The 1.5 changes are an important step for Java. Personally I'll be waiting until I thoroughly understand what they can do before I start trying to figure out what's missing.
Dave.