From 7094c7b7976e88bb65b71009ac7501025ca31bc3 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Fri, 10 Apr 2015 15:46:53 +0200 Subject: [PATCH] Dereference when calling PooledByteBuf.deallocate() Motivation: We missed to dereference the chunk and tmpNioBuf when calling deallocate(). This means the GC can not collect these as we still hold a reference while have the PooledByteBuf in the recycler stack. Modifications: Dereference chunk and tmpNioBuf. Result: GC can collect things. --- buffer/src/main/java/io/netty/buffer/PooledByteBuf.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/buffer/src/main/java/io/netty/buffer/PooledByteBuf.java b/buffer/src/main/java/io/netty/buffer/PooledByteBuf.java index 980c4541b4..0d7f4a23d2 100644 --- a/buffer/src/main/java/io/netty/buffer/PooledByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/PooledByteBuf.java @@ -143,10 +143,14 @@ abstract class PooledByteBuf extends AbstractReferenceCountedByteBuf { if (handle >= 0) { final long handle = this.handle; this.handle = -1; - memory = null; boolean sameThread = initThread == Thread.currentThread(); - initThread = null; chunk.arena.free(chunk, handle, maxLength, sameThread); + // Dereference everything so GC can do it's work. + chunk = null; + tmpNioBuf = null; + initThread = null; + memory = null; + recycle(); } }