Issue Details (XML | Word | Printable)

Key: LUCENE-1383
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Michael McCandless
Reporter: Michael McCandless
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Lucene - Java

Work around ThreadLocal's "leak"

Created: 11/Sep/08 08:50 PM   Updated: 11/Oct/08 12:49 PM
Return to search
Component/s: Index
Affects Version/s: 1.9, 2.0.0, 2.1, 2.2, 2.3, 2.3.1, 2.3.2
Fix Version/s: 2.4

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works LUCENE-1383.patch 2008-09-11 09:04 PM Michael McCandless 7 kB
Image Attachments:

1. ScreenHunter_01 Sep. 13 08.40.jpg
(15 kB)

2. ScreenHunter_02 Sep. 13 08.42.jpg
(16 kB)

3. ScreenHunter_03 Sep. 13 08.43.jpg
(16 kB)

4. ScreenHunter_07 Sep. 13 19.13.jpg
(17 kB)

Lucene Fields: New
Resolution Date: 14/Sep/08 10:33 AM


 Description  « Hide
Java's ThreadLocal is dangerous to use because it is able to take a
surprisingly very long time to release references to the values you
store in it. Even when a ThreadLocal instance itself is GC'd, hard
references to the values you had stored in it are easily kept for
quite some time later.

While this is not technically a "memory leak", because eventually
(when the underlying Map that stores the values cleans up its "stale"
references) the hard reference will be cleared, and GC can proceed,
its end behavior is not different from a memory leak in that under the
right situation you can easily tie up far more memory than you'd
expect, and then hit unexpected OOM error despite allocating an
extremely large heap to your JVM.

Lucene users have hit this many times. Here's the most recent thread:

http://mail-archives.apache.org/mod_mbox/lucene-java-dev/200809.mbox/%3C6e3ae6310809091157j7a9fe46bxcc31f6e63305fcdc%40mail.gmail.com%3E

And here's another:

http://mail-archives.apache.org/mod_mbox/lucene-java-dev/200807.mbox/%3CF5FC94B2-E5C7-40C0-8B73-E12245B91CEE%40mikemccandless.com%3E

And then there's LUCENE-436 and LUCENE-529 at least.

A google search for "ThreadLocal leak" yields many compelling hits.

Sun does this for performance reasons, but I think it's a terrible
trap and we should work around it with Lucene.



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
No work has yet been logged on this issue.