lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McCandless <>
Subject Re: ThreadLocal in SegmentReader
Date Fri, 11 Jul 2008 10:29:00 GMT

After discussing this on java-dev:

it seems that this is not in fact a leak but rather a delayed GC  
issue.  The objects are eventually freed, on Sun 1.4, 1.5 and 1.6.

When a ThreadLocal instance becomes unreferenced & GC'd, Java does not  
immediately reclaim the now-unreferenced objects, if the thread  
remains alive.  However, over time, as other ThreadLocals are used  
with that thread, those stale objects do eventually get reclaimed.  So  
my feeling for now is it's OK for Lucene to continue to use non-static  


Yonik Seeley wrote:

> On Mon, Jul 7, 2008 at 2:43 PM, Michael McCandless
> <> wrote:
>> So now I'm confused: the SegmentReader itself should no longer be  
>> reachable,
>> assuming you are not holding any references to your IndexReader.
>> Which means the ThreadLocal instance should no longer be reachable.
> It will still be referenced from the Thread(s) ThreadLocalMap
> The key (the ThreadLocal) will be weakly referenced, but the values
> (now stale) are strongly referenced and won't be actually removed
> until the table is resized (under the Java6 impl at least).
> Nice huh?
> -Yonik
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message