--- Brian Stansberry <[EMAIL PROTECTED]>
wrote:
<snip>
>
> This line of thought led me to reconsider an idea
> I'd
> rejected a couple weeks back related to the JCL
> memory
> leak problem. Basically the leak occurs if
> LogFactoryImpl is defined by a parent classloader
> while the class of one of its Log instances is
> defined
> by a child loader. The chain of references from the
> Log instance to its classloader will prevent gc of
> the
> child loader on undeploy.
>
> This chain could (potentially) be broken if
> LogFactoryImpl only held WeakReferences to its Log
> instances as follows:
>
> public Log getInstance(String name) throws
> LogConfigurationException {
> -
> - Log instance = (Log) instances.get(name);
> - if (instance == null) {
> - instance = newInstance(name);
> - instances.put(name, instance);
> +
> + Log instance = null;
> + WeakReference ref = (WeakReference)
> instances.get(name);
> + if (ref != null) {
> + instance = (Log) instances.get(name);
> + if (instance == null) {
> + instance = newInstance(name);
> + instances.put(name, new
> WeakReference(instance));
> + }
> }
> return (instance);
Oops. Try:
public Log getInstance(String name) throws
LogConfigurationException {
-
- Log instance = (Log) instances.get(name);
- if (instance == null) {
- instance = newInstance(name);
- instances.put(name, instance);
+
+ Log instance = null;
+ WeakReference ref = (WeakReference)
instances.get(name);
+ if (ref != null) {
+ instance = (Log) instances.get(name);
+ }
+ if (instance == null) {
+ instance = newInstance(name);
+ instances.put(name, new
WeakReference(instance));
+ }
return (instance);
Brian
__________________________________
Yahoo! Messenger
Show us what our next emoticon should look like. Join the fun.
http://www.advision.webevents.yahoo.com/emoticontest
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]