|
@@ -25,10 +25,10 @@ import org.elasticsearch.common.util.Maps;
|
|
|
import org.elasticsearch.common.xcontent.ChunkedToXContent;
|
|
|
import org.elasticsearch.common.xcontent.XContentHelper;
|
|
|
import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
|
|
-import org.elasticsearch.core.AbstractRefCounted;
|
|
|
import org.elasticsearch.core.Nullable;
|
|
|
import org.elasticsearch.core.RefCounted;
|
|
|
import org.elasticsearch.core.RestApiVersion;
|
|
|
+import org.elasticsearch.core.SimpleRefCounted;
|
|
|
import org.elasticsearch.index.mapper.IgnoredFieldMapper;
|
|
|
import org.elasticsearch.index.mapper.MapperService;
|
|
|
import org.elasticsearch.index.mapper.SourceFieldMapper;
|
|
@@ -204,21 +204,7 @@ public final class SearchHit implements Writeable, ToXContentObject, RefCounted
|
|
|
this.innerHits = innerHits;
|
|
|
this.documentFields = documentFields;
|
|
|
this.metaFields = metaFields;
|
|
|
- this.refCounted = refCounted == null ? LeakTracker.wrap(new AbstractRefCounted() {
|
|
|
- @Override
|
|
|
- protected void closeInternal() {
|
|
|
- if (SearchHit.this.innerHits != null) {
|
|
|
- for (SearchHits h : SearchHit.this.innerHits.values()) {
|
|
|
- h.decRef();
|
|
|
- }
|
|
|
- SearchHit.this.innerHits = null;
|
|
|
- }
|
|
|
- if (SearchHit.this.source instanceof RefCounted r) {
|
|
|
- r.decRef();
|
|
|
- }
|
|
|
- SearchHit.this.source = null;
|
|
|
- }
|
|
|
- }) : ALWAYS_REFERENCED;
|
|
|
+ this.refCounted = refCounted == null ? LeakTracker.wrap(new SimpleRefCounted()) : ALWAYS_REFERENCED;
|
|
|
}
|
|
|
|
|
|
public static SearchHit readFrom(StreamInput in, boolean pooled) throws IOException {
|
|
@@ -726,7 +712,24 @@ public final class SearchHit implements Writeable, ToXContentObject, RefCounted
|
|
|
|
|
|
@Override
|
|
|
public boolean decRef() {
|
|
|
- return refCounted.decRef();
|
|
|
+ if (refCounted.decRef()) {
|
|
|
+ deallocate();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void deallocate() {
|
|
|
+ if (SearchHit.this.innerHits != null) {
|
|
|
+ for (SearchHits h : SearchHit.this.innerHits.values()) {
|
|
|
+ h.decRef();
|
|
|
+ }
|
|
|
+ SearchHit.this.innerHits = null;
|
|
|
+ }
|
|
|
+ if (SearchHit.this.source instanceof RefCounted r) {
|
|
|
+ r.decRef();
|
|
|
+ }
|
|
|
+ SearchHit.this.source = null;
|
|
|
}
|
|
|
|
|
|
@Override
|