lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McCandless <>
Subject Re: Does a IndexSearcher call incRef on the underlying reader?
Date Wed, 27 Oct 2010 16:52:34 GMT
When you run a search, you call SearcherManager.get to obtain the
current searcher.

That does an incRef.

So if while this query is running a new searcher is swapped in, the
query is still save because it's holding a reference.  Ie the reader
will have a refCount of 1 at that point.

Then when the search finishes and calls SearcherManager.release, that
drops the readers refCount to 0, which closes it.

Note, though, that you must still lose your reference to the reader to
allow GC to clean it up!


On Wed, Oct 27, 2010 at 12:48 PM, Pulkit Singhal
<> wrote:
> @Question2: Also I was wondering what happens to the code that may have been
> using the searcher which got swapped out in SearcherManager? Does that
> IndexSearcher continue to run and when it finishes the GC is free to collect
> it? OR will the fact that the reader for that searcher has had its last
> decRef() call take the reader's internal count to 0 ... cause someone who is
> paging through results to see the server choking with exceptions?
> On Wed, Oct 27, 2010 at 12:35 PM, Pulkit Singhal <>wrote:
>> Hello,
>> I have been looking at the SearcherManager example provided in the "Lucene
>> In Action 2nd Edition" book. It seems like a great way to manage
>> IndexReaders but I had a few questions about the Lucene API that poppedup
>> after reading it:
>> @Question: Does a IndexSearcher call upon an IndexReader's incRef() method
>> internally when the reader is passed in as an argument to the searcher's
>> constructor?
>> @Motivation: I ask because, if that is the case then I will need to make an
>> additional call to decRef(). Also the book claims that
>> "IndexSearcher.close() is a no-op if you provide an already opened
>> IndexReader when creating the IndexSearcher" so I guess I can't count on
>> that close() method to call the decRef() method for me and I must call it
>> myself?  Once again, I'm thinking of doing all this only if incRef() was
>> called on the reader in the searcher's constructor, which I'm hoping someone
>> will confirm for me.
>> Thanks,
>> - Pulkit

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

View raw message