The finalize() thing does not work correctly, as the reader holds still
references to other stuff when not explicitely closed. As it references
them, the finalizer() is never called, as it is not to be gc'd.

You must close the reader explicit, that's all. So just close it afterusing.
With Near Realtime Search, you normally get an IR, then wrap it with
IndexSearcher, do your search, and close it after that. You can even call
writer.getReader() from different threads, refcounting will close the
readers correctly. So for each request, take a new one and close after
usage.

Uwe

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: u...@thetaphi.de


> -----Original Message-----
> From: Jamie [mailto:ja...@stimulussoft.com]
> Sent: Wednesday, September 29, 2010 11:50 AM
> To: java-user@lucene.apache.org
> Subject: Re: File Handle Leaks During Lucene 3.0.2 Merge
> 
>   Hi Uwe
> 
> Thanks in advance for your help. Well, I just tried searching again and it
made
> no difference. My LuceneIndex getReader() function will call
> writer.getReader() on occasion or return a cached copy. To make sure that
> IndexReader's are closed when they are no longer needed, I wrap the
> IndexReader as follows:
> 
> public class VolumeIndexReader extends FilterIndexReader {
> 
>      public VolumeIndexReader(IndexReader in) {
>          super(in);
>      }
> 
>      public void finalize() {
>          try { in.close(); } catch (Exception e) {}
>      }
> 
>      public IndexReader reopen(boolean readonly) throws IOException {
>          return super.reopen(readonly);
>      }
> }
> 
> You'll notice finalizer calls IndexReader.close(). After users conduct
multiple
> searches, the index reader should be closed in time. Therefore, its
confusing to
> me to see that open handles are still present. Clearly, I am doing
something
> wrong, but what?
> 
> Jamie
> 
> 
> 
> On 2010/09/29 8:21 PM, Uwe Schindler wrote:
> > The "deleted" files are only freed by OS kernel if no longer an
> > IndexReader accesses them. Did you get a new realtime reader after
> > merging and*closed* the old one?
> >
> > -----
> > Uwe Schindler
> > H.-H.-Meier-Allee 63, D-28213 Bremen
> > http://www.thetaphi.de
> > eMail:u...@thetaphi.de



---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org

Reply via email to