lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Heng Mei" <heng....@gmail.com>
Subject Re: IndexSearcher memory leak?
Date Thu, 06 Jul 2006 04:50:35 GMT
Thanks for the fast response -- you're right, I had a typo in the code snippet.

I've attached the test code that reproduces the OutOfMemoryException.
The code is a simple main method that repeatedly opens/searches/closes
an index using RAMDirectory.  Maybe there's something I'm overlooking,
but it appears that when the Searcher is declared outside of the loop,
that's when the OutOfMemoryException occurs.  If the searcher is
declared inside of the loop, then there's no memory problem.

The motivation for this test code is that I plan to write a
long-running server that periodically reopens an index -- so clearly
I'd want to be able to close and open the index without leaking any
memory.

Any insight on why the memory exception occurs and how to resolve it
would be greatly appreciated.


Thanks!
~Heng

On 7/5/06, Chris Hostetter <hossman_lucene@fucit.org> wrote:
> : I get an OutOfMemoryException after a few iterations of the following loop:
> : LOOP:
> :       ramdir = new RAMDirectory( "path/to/my/directory" );
> :       searcher = new IndexSearcher( reader );
> :         searcher.search(new TermQuery( new Term( "field", "keyword")));
> :         searcher.close();
> :         ramdir.close();
> : END LOOP:
> : Note, ramdir and searcher are both instance variables.
>
> But what is "reader" ?  .. where is it initialized ?
>
> I'm guessing this isn't hte exact code that gives you an OOM (since there
> seems to be some code missing)
>
> if you can post a complete small example program (with main method) that
> demonstrates this problem -- or even better a self contained JUNit test --
> then people can try to reproduce it.
>
> (if the root of the issue is opening a RAMDirectory based on an
> FSDirectory you can create the on disk directory using the system tmpdir
> in your JUnit setUp method)
>
> I suspect that somewhere in there you have another line that looks like...
>
>      reader = IndexReader.open( ramdir );
>
> ...and that may be causing your problem.   If you open an IndexReader
> explicitly, then IndexSearcher.close() won't close it for you
>
>
>
>
>
> -Hoss
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>


Mime
View raw message