lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Miller <markrmil...@gmail.com>
Subject Re: Lucene Memory Leak
Date Tue, 02 Sep 2008 19:58:53 GMT
You should really close the IndexSearcher rather than the directory.

Andy33 wrote:
> I have a memory leak in my lucene search code. I am able to run a few queries
> fine, but I eventually run out of memory. Please note that I do close and
> set to null the ivIndexSearcher object elsewhere. Here is the code I am
> using... 
>
>
> private synchronized Hits doQuery(String field, String queryStr, Sort
> sortOrder, String indexDirectory) throws Exception
>     {
> 	Directory directory = null;
> 	
> 	try
> 	{
> 	    Analyzer analyzer = new StandardAnalyzer();
> 	    
> 	    directory = FSDirectory.getDirectory(indexDirectory);
> 	    
> 	    //search the index
> 	    ivIndexSearcher = new IndexSearcher(directory);
> 	       
> 	    QueryParser parser = new QueryParser(field, analyzer);
> 	    Query query = parser.parse(queryStr);
> 	    Hits results = ivIndexSearcher.search(query, sortOrder);
> 	    
> 	    return results;
> 	}	
> 	finally
> 	{	   
> 	    if(null != directory)
> 	    {
> 		directory.close();
> 	    }
> 	    directory = null;
> 	}
>     }
>   


---------------------------------------------------------------------
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