Friday, May 11, 2007

JavaOne 2007 day 3, Garbage Collection friendly coding.

This was i nice and fun session.

If you just want to remember one thing from this its: DONT use finalize method for anything in java. The other things are normal memmory misuse stuff.
1. Always declare an Collection(impl) to an approx size of what u want, it not as sheap as one thinks to resize collections.
2. Small, immutable objects are really fast for the GC. Dont be clever and create them outside the loop or the normal life scope of the variable. Do not create generic variables that are nullified and reused in a method or loop.
3. Be aware of actionlisteners these keep reference to our instance and can create memmory leaks. This kind of behaivure is not as uncommon as one might think, even others than the AWT-tam make these kinds of programs.
4. If unclear dont use finalize, ever. DONT use them. If something like this i really needed, no other way can solve the problem, then use Reference classes(java.lang.ref.PhantomReference) and wrap the instance that needs this.

There were more tips, but i cant remember them all.

1 comment:

Barnabas said...

BEA actually promises semi real time execution SLA's on methods running on WLS on JRocket in the next version.

I have been trying to figure out how they work around the fact, that their JVM is most likely to run in a multi tasking environment.

And as a consequence of this - it will be very hard to guarantee anything at all on such a platform.