I'd really like to know what folks are doing for this if anything.  I just
tracked down a memory leak on our web application server, at it was related
to the static references in the NDC.

In tracking down the memory leak, I noticed that some HttpServletRequest
objects were hanging about.  I thought that was strange, as those should get
freed after the request is processed.  When I looked at what was referencing
them, it was the static reference in the NDC is every case.

I subsequently added a call to NDC.remove() (after the last pop) and the
memory leak went away, completely.  So, be aware.

There doesn't seem to be much overhead in calling NDC.remove().  It is
strange to me that the request object was being used as a reference and not
the thread.  I haven't looked at the NDC code though.

Any comments or insights?
-Mark


-----Original Message-----
From: Ceki Gülcü [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 14, 2001 11:45 PM
To: LOG4J Users Mailing List
Subject: Re: When to call NDC::remove



Ray,

This is from the NDC javadoc:

Heavy duty systems should call the remove() method when leaving the run
method of a thread. This ensures that the memory used by the thread can be
freed by the Java garbage collector. There is a mechanism to lazily remove
references to dead threads. In practice, this means that you can be a little
sloppy and sometimes forget to call remove() before exiting a thread. 

The problem in your case is that you do not control the life cycle of the
calling thread. Have you considered calling NDC remove at the end of the
HTTP request? Regards, Ceki

ps: Interesting problem by the way.

At 17:13 14.08.2001 -0500, Millard, Ray wrote:
>We are working in a J2EE Model II environment.  In various mail threads,
>users have mentioned that there are several possible locations to call
>NDC::remove, however, I haven't been able to find a thread that mentions
>exactly where different organizations are calling it.  I have thought about
>the following scenario:
>
>1. In the doGet/doPost, call NDC.push("something unique about the user");
>2. At the end of the doGet/doPost call NDC.pop();
>3. In the servlet finalize method call NDC::remove.
>
>I am not sure that this scenario will work to reclaim the memory, as I do
>not know if the log4J framework holds a reference to the servlet and thus
>prevents the finalize method from being called.  If you are using NDCs in a
>Model II environment, please respond back with your NDC scenario.
>
>Thanks!

--
Ceki Gülcü - http://qos.ch


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to