Skip to content

Commit 257494e

Browse files
Unlink delegate in ReleasableBytesReference once ref count reaches 0
We have some spots where we retain a reference to the `ReleasableBytesReference` instance well beyond its ref-count reaching `0`. If it itself references Netty buffers or `BigArrays` that are not pooled (mostly as a result of overflowing the pooled number of bytes for large messages or under heavy load) then those bytes are not GC-able unless we unlink them here.
1 parent 75f8e4a commit 257494e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

server/src/main/java/org/elasticsearch/common/bytes/ReleasableBytesReference.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public final class ReleasableBytesReference implements RefCounted, Releasable, B
2929

3030
private static final ReleasableBytesReference EMPTY = new ReleasableBytesReference(BytesArray.EMPTY, RefCounted.ALWAYS_REFERENCED);
3131

32-
private final BytesReference delegate;
32+
private BytesReference delegate;
3333
private final RefCounted refCounted;
3434

3535
public static ReleasableBytesReference empty() {
@@ -63,7 +63,11 @@ public boolean tryIncRef() {
6363

6464
@Override
6565
public boolean decRef() {
66-
return refCounted.decRef();
66+
boolean res = refCounted.decRef();
67+
if (res) {
68+
delegate = null;
69+
}
70+
return res;
6771
}
6872

6973
@Override

0 commit comments

Comments
 (0)