clean unused memory by SegmentReader

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1529611 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2013-10-06 11:47:56 +00:00
parent 3bdd7f1b16
commit 2529b4799e
1 changed files with 18 additions and 7 deletions

View File

@ -47,6 +47,18 @@ import org.apache.lucene.util.RefCount;
*/
public final class SegmentReader extends AtomicReader {
private static final class DocValuesRefCount extends RefCount<DocValuesProducer> {
public DocValuesRefCount(DocValuesProducer object) {
super(object);
}
@Override
protected void release() throws IOException {
object.close();
}
}
private final SegmentInfoPerCommit si;
private final Bits liveDocs;
@ -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<DocValuesProducer>(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;