From 2529b4799e0e4e6a1fd04ec59c8b855926883835 Mon Sep 17 00:00:00 2001 From: Shai Erera Date: Sun, 6 Oct 2013 11:47:56 +0000 Subject: [PATCH] clean unused memory by SegmentReader git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1529611 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/index/SegmentReader.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentReader.java b/lucene/core/src/java/org/apache/lucene/index/SegmentReader.java index fbead6a75ac..659277e932b 100644 --- a/lucene/core/src/java/org/apache/lucene/index/SegmentReader.java +++ b/lucene/core/src/java/org/apache/lucene/index/SegmentReader.java @@ -47,6 +47,18 @@ import org.apache.lucene.util.RefCount; */ public final class SegmentReader extends AtomicReader { + private static final class DocValuesRefCount extends RefCount { + + public DocValuesRefCount(DocValuesProducer object) { + super(object); + } + + @Override + protected void release() throws IOException { + object.close(); + } + } + private final SegmentInfoPerCommit si; private final Bits liveDocs; @@ -261,7 +273,7 @@ public final class SegmentReader extends AtomicReader { return genInfos; } - private RefCount newDocValuesProducer(SegmentInfoPerCommit si, IOContext context, Directory dir, + private RefCount newDocValuesProducer(SegmentInfoPerCommit si, IOContext context, Directory dir, DocValuesFormat dvFormat, Long gen, List infos) throws IOException { Directory dvDir = dir; String segmentSuffix = ""; @@ -272,12 +284,7 @@ public final class SegmentReader extends AtomicReader { // set SegmentReadState to list only the fields that are relevant to that gen SegmentReadState srs = new SegmentReadState(dvDir, si.info, new FieldInfos(infos.toArray(new FieldInfo[infos.size()])), context, segmentSuffix); - return new RefCount(dvFormat.fieldsProducer(srs)) { - @Override - protected void release() throws IOException { - object.close(); - } - }; + return new DocValuesRefCount(dvFormat.fieldsProducer(srs)); } @Override @@ -302,6 +309,10 @@ public final class SegmentReader extends AtomicReader { } } } + genDVProducers.clear(); + dvProducers.clear(); + docValuesLocal.close(); + docsWithFieldLocal.close(); if (t != null) { if (t instanceof IOException) throw (IOException) t; if (t instanceof RuntimeException) throw (RuntimeException) t;