Null out references to tmpNioBuf and chunk to allow quicker collecting
Motivation: In PooledByteBuf we missed to null out the chunk and tmpNioBuf fields before recycle it to the Recycler. This could lead to keep objects longer alive then necessary which may hold a lot of memory. Modifications: Null out tmpNioBuf and chunk before recycle. Result: Possible to earlier GC objects.
This commit is contained in:
parent
f4c2c1926f
commit
8dda984afe
@ -34,6 +34,7 @@ abstract class PooledByteBuf<T> extends AbstractReferenceCountedByteBuf {
|
|||||||
int maxLength;
|
int maxLength;
|
||||||
PoolThreadCache cache;
|
PoolThreadCache cache;
|
||||||
private ByteBuffer tmpNioBuf;
|
private ByteBuffer tmpNioBuf;
|
||||||
|
private ByteBufAllocator allocator;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected PooledByteBuf(Recycler.Handle<? extends PooledByteBuf<T>> recyclerHandle, int maxCapacity) {
|
protected PooledByteBuf(Recycler.Handle<? extends PooledByteBuf<T>> recyclerHandle, int maxCapacity) {
|
||||||
@ -48,6 +49,7 @@ abstract class PooledByteBuf<T> extends AbstractReferenceCountedByteBuf {
|
|||||||
this.chunk = chunk;
|
this.chunk = chunk;
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
memory = chunk.memory;
|
memory = chunk.memory;
|
||||||
|
allocator = chunk.arena.parent;
|
||||||
this.offset = offset;
|
this.offset = offset;
|
||||||
this.length = length;
|
this.length = length;
|
||||||
this.maxLength = maxLength;
|
this.maxLength = maxLength;
|
||||||
@ -123,7 +125,7 @@ abstract class PooledByteBuf<T> extends AbstractReferenceCountedByteBuf {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final ByteBufAllocator alloc() {
|
public final ByteBufAllocator alloc() {
|
||||||
return chunk.arena.parent;
|
return allocator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -168,7 +170,9 @@ abstract class PooledByteBuf<T> extends AbstractReferenceCountedByteBuf {
|
|||||||
final long handle = this.handle;
|
final long handle = this.handle;
|
||||||
this.handle = -1;
|
this.handle = -1;
|
||||||
memory = null;
|
memory = null;
|
||||||
|
tmpNioBuf = null;
|
||||||
chunk.arena.free(chunk, handle, maxLength, cache);
|
chunk.arena.free(chunk, handle, maxLength, cache);
|
||||||
|
chunk = null;
|
||||||
recycle();
|
recycle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user