commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sandy McArthur" <sandy...@apache.org>
Subject Re: Log4j String buffer memory Leak.
Date Wed, 07 Jun 2006 20:47:11 GMT
On 6/7/06, Naveen <naween18@yahoo.com> wrote:
> Thanks a lot sandy and Oliver ..
>   but the issue remains...Mercury Diagnosis tools reports lot of Sting Buffer being created
at that particular method call and never being released. Iam stuck in middle and have no clue
what so ever.

Well, if what you are saying is true, specifically that the Mercury
Diagnostics tool claims that line is creating StringBuffers and never
allowing them to be garbage collected, then tell your boss that I say
the tool is unreliable and remind him that the tool is an aid to help
you but in the end it's up to you to apply your intelligence. (Not
that your boss has any reason to put any weight in what some random
Internet person has to say. :-)

If the tool is just identifying potentially wasted object creating
then yes, it's correct and other than the if
(logger.isSomeLevelEnabled()) idiom there isn't much you can do.

My personal opinion is unless you have gobs of spare time, don't worry
about this type of issue as it's really a small problem compared to
the performance characteristics of any meaningful application I've
worked on.

My experience is profilers produce a lot of noise and you should
consider its output a list of potential places to improve your code
but only handful of those places will have a meaningful effect if you
improve them.

>   Our company is in process of evaluating Mercury Diagnosis tool and they really want
us to go by the tool reports and make the changes . Iam stuck at this place and not sure what
change to make.

The code you describe is so common and so simple that it would have
been identified long ago by many people had there been a real problem
there.

A good rule of thumb is If your code works well enough, then don't
change it if you don't have to because the change may break something.

> Sandy McArthur <sandymac@apache.org> wrote:
>   Naveen,
>
> That sample code will result in a String being passed to debug or
> info. The StringBuffer used internally by the compiler will be
> available for garbage collection after the StringBuffer is converted
> to a String and before the resulting String is passed as a parameter.
>
> There isn't a memory leak there as much as maybe wasted work done in
> object creation to create the method parameter. Using the if
> (logger.isDebugEnabled()) idiom Oliver suggested will save that work.
>
> I'm not familar with Mercury but if it really reports a leak there
> then it's probably false positive.
>
> On 6/7/06, Naveen wrote:
> > Hello all,
> >
> > Iam not sure if there is really amemory leak in Log4jLogger. We use Mercury diagnosis
tool to find the memory leak and the reports show all the string buffers being held up at
> >
> > 1. org.apache.log4j.Logger.debug
> > 2. org.apache.log4j.Logger.info
> >
> > this is one of the call we make
> >
> > logger.debug(connectionID + "-" + message);
> >
> > logger is an instance of Log4j.Logger and connectionID,message are strings
> >
> > i know appending strings will internally create StrinBuffers but our memory reports
show string buffers are never cleared which are areated during that call.
> >
> > any help is highly appreciated.
> >
> > Thanks,
> > Naveen.
> >
> >
> >
> >
> >
> >
> > Naveen
> >
> > It only takes a moment to be kind, but the results can be everlasting.!!
> >
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam? Yahoo! Mail has the best spam protection around
> > http://mail.yahoo.com
> >
>
>
> --
> Sandy McArthur
>
> "He who dares not offend cannot be honest."
> - Thomas Paine
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>
>
>     Naveen
>
>   It only takes a moment to be kind, but the results can be everlasting.!!
>
>
>
>  __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>


-- 
Sandy McArthur

"He who dares not offend cannot be honest."
- Thomas Paine

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message