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:
Norman Maurer 2017-01-25 20:12:45 +01:00
parent 2f4298a419
commit dcf4292647

View File

@ -33,6 +33,7 @@ abstract class PooledByteBuf<T> extends AbstractReferenceCountedByteBuf {
int maxLength;
PoolThreadCache cache;
private ByteBuffer tmpNioBuf;
private ByteBufAllocator allocator;
protected PooledByteBuf(Recycler.Handle recyclerHandle, int maxCapacity) {
super(maxCapacity);
@ -46,6 +47,7 @@ abstract class PooledByteBuf<T> extends AbstractReferenceCountedByteBuf {
this.chunk = chunk;
this.handle = handle;
memory = chunk.memory;
allocator = chunk.arena.parent;
this.offset = offset;
this.length = length;
this.maxLength = maxLength;
@ -121,7 +123,7 @@ abstract class PooledByteBuf<T> extends AbstractReferenceCountedByteBuf {
@Override
public final ByteBufAllocator alloc() {
return chunk.arena.parent;
return allocator;
}
@Override
@ -150,7 +152,9 @@ abstract class PooledByteBuf<T> extends AbstractReferenceCountedByteBuf {
final long handle = this.handle;
this.handle = -1;
memory = null;
tmpNioBuf = null;
chunk.arena.free(chunk, handle, maxLength, cache);
chunk = null;
recycle();
}
}