If I don't keep the IndexSearcher as a Singleton and instead open and close a new one each time, I have a large memory leak (probably due to the large queries I am doing). After watching the memory a while, I still believe I have a small memory leak even when the Directory, Analyzer, and IndexSearcher are Singletons. My free memory slowly becomes smaller after each query. Any ideas on what that may be due to?
Here's my updated code... private synchronized Hits doQuery(String field, String queryStr, Sort sortOrder, String indexDirectory) throws Exception { Directory directory = null; Query query = null; QueryParser parser = null; try { directory = DirectorySingleton.getInstance(indexDirectory); ivIndexSearcher = (IndexSearcher) SearcherSingleton.getInstance(directory); //search the index parser = new QueryParser(field, AnalyzerSingleton.getInstance()); query = parser.parse(queryStr); return ivIndexSearcher.search(query, sortOrder); } finally { if(null != directory) { directory.close(); } directory = null; parser = null; query = null; } } -------------- Example Singleton public class SearcherSingleton { private static volatile HashMap<Directory, Searcher> cvSearches = new HashMap<Directory, Searcher>(); protected SearcherSingleton() { } public static Searcher getInstance(Directory directory) throws IOException { if(!cvSearches.containsKey(directory)) { synchronized(SearcherSingleton.class) { if(!cvSearches.containsKey(directory)) { cvSearches.put(directory, new IndexSearcher(directory)); } } } return cvSearches.get(directory); } } 장용석 wrote: > > In fact, I think that the important reasons are Directory class and > Analyzer > class. > If you don't want IndexSearcher class keep open for the entire life of a > web > application, you can do it. > I think It will not cause memory leak problem. > But, Directory and Analyzer classes can cause the problem if they new > created by method call every time. I think... > Only keep two classes Directory and Analyzer by singlton and do test. :) > > -- View this message in context: http://www.nabble.com/Lucene-Memory-Leak-tp19276999p19333985.html Sent from the Lucene - Java Users mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]