From 6839cc6965fcbfcf28487268f7a5b9fe04d5b580 Mon Sep 17 00:00:00 2001 From: kimchy Date: Fri, 12 Nov 2010 15:36:23 +0200 Subject: [PATCH] clear memory after parsing a doc, and not on parsing of a new doc --- .../org/elasticsearch/common/lucene/DocumentBuilder.java | 2 ++ .../index/mapper/xcontent/XContentDocumentMapper.java | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/DocumentBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/DocumentBuilder.java index 5c3163c81c3..d54207c6e0e 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/DocumentBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/DocumentBuilder.java @@ -28,6 +28,8 @@ import org.apache.lucene.document.Fieldable; */ public class DocumentBuilder { + public static final Document EMPTY = new Document(); + public static DocumentBuilder doc() { return new DocumentBuilder(); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentDocumentMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentDocumentMapper.java index 44a49a046f8..05dfa365722 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentDocumentMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/XContentDocumentMapper.java @@ -391,7 +391,10 @@ public class XContentDocumentMapper implements DocumentMapper, ToXContent { parser.close(); } } - return new ParsedDocument(context.uid(), context.id(), context.type(), context.doc(), context.analyzer(), source, context.mappersAdded()); + ParsedDocument doc = new ParsedDocument(context.uid(), context.id(), context.type(), context.doc(), context.analyzer(), source, context.mappersAdded()); + // reset the context to free up memory + context.reset(null, null, null, null, null); + return doc; } void addFieldMapper(FieldMapper fieldMapper) {