Marc,
This is very _bad_ practice. There is no need to drop references, that's
what GC is all about. If the containing object is able to be finalized,
then it is about to be collected and the reference will drop anyway. Worse,
by adding a finalize to your class you make extra work for the garbage
collector and block several possible optimizations, slowing down the release
of memory.
Typically the only time you need to use finalize is when writing wrappers
for non-memory resources, such as file handles, database connections, and
the like. Even then, it is better practice to also implement an explicit
close method to drop the resource.
If your web application holds onto the log from an object that cannot be
garbage collected, then neither finalize nor GC will help you. You will
need to make an explicit call to drop the reference somewhere, or possibly
consider using the java.lang.ref classes to modify how your reference to the
log is handled by the collector.
Stuart Halloway
DevelopMentor
http://staff.develop.com/halloway
> Components of my application use a log manager, which implements the
> singleton instance pattern. When a component wishes to log messages it
> calls the log managers getInstance method, which returns the one and only
> instance of the log manager class.
>
> When I decide to shut down the web application each component has
> a finalize
> method which sets the variable that contains the log manager instance to
> null.
>
> Now my understanding is that this is good practise since the garbage
> collector will not clean up objects until all references (handles to it)
> have been dropped. So by getting each component to set its own variable
> (that hows the log manager reference) to null I am speeding up the release
> of memory.
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html