Return-Path: Delivered-To: apmail-lucene-java-dev-archive@www.apache.org Received: (qmail 66113 invoked from network); 11 Jun 2008 18:17:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Jun 2008 18:17:42 -0000 Received: (qmail 9614 invoked by uid 500); 11 Jun 2008 18:17:41 -0000 Delivered-To: apmail-lucene-java-dev-archive@lucene.apache.org Received: (qmail 9519 invoked by uid 500); 11 Jun 2008 18:17:40 -0000 Mailing-List: contact java-dev-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-dev@lucene.apache.org Delivered-To: mailing list java-dev@lucene.apache.org Received: (qmail 9510 invoked by uid 99); 11 Jun 2008 18:17:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Jun 2008 11:17:40 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Jun 2008 18:16:57 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 0500B234C137 for ; Wed, 11 Jun 2008 11:16:45 -0700 (PDT) Message-ID: <253424766.1213208205019.JavaMail.jira@brutus> Date: Wed, 11 Jun 2008 11:16:45 -0700 (PDT) From: "Ethan Tao (JIRA)" To: java-dev@lucene.apache.org Subject: [jira] Created: (LUCENE-1304) Memory Leak when using Custom Sort (i.e., DistanceSortSource) of LocalLucene with Lucene MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Memory Leak when using Custom Sort (i.e., DistanceSortSource) of LocalLucene with Lucene ---------------------------------------------------------------------------------------- Key: LUCENE-1304 URL: https://issues.apache.org/jira/browse/LUCENE-1304 Project: Lucene - Java Issue Type: Bug Components: Search Affects Versions: 2.3 Environment: Windows/JDK 1.6 Reporter: Ethan Tao We had the memory leak issue when using DistanceSortSource of LocalLucene for repeated query/search. In about 450 queries, we are experiencing out of memory error. After dig in the code, we found the problem source is coming from Lucene package, the way how it handles "custom" type comparator. Lucene internally caches all created comparators. In the case of query using LocalLucene, we create new comparator for every search due to different lon/lat and query terms. This causes major memory leak as the cached comparators are also holding memory for other large objects (e.g., bit sets). The solution we came up with: ( the proposed change from Lucene is 1 and 3 below) 1. In Lucene package, create new file SortComparatorSourceUncacheable.java: package org.apache.lucene.search; import org.apache.lucene.index.IndexReader; import java.io.IOException; import java.io.Serializable; public interface SortComparatorSourceUncacheable extends Serializable { } 2. Have your custom sort class to implement the interface public class LocalSortSource extends DistanceSortSource implements SortComparatorSourceUncacheable { ... } 3. Modify Lucene's FieldSorterHitQueue.java to bypass caching for custom sort comparator: Index: FieldSortedHitQueue.java =================================================================== --- FieldSortedHitQueue.java (revision 654583) +++ FieldSortedHitQueue.java (working copy) @@ -53,7 +53,12 @@ this.fields = new SortField[n]; for (int i=0; i