[#3837] Null out ByteBuffer[] array once done
Motivation: the ByteBuffer[] that we keep in the ThreadLocal are never nulled out which can lead to have ByteBuffer instances sit there forever. This is even a bigger problem if nioBuffer() of ByteBuffer returns a new ByteBuffer that can not be destroyed by ByteBuffer.release(). Modifications: Null out ByteBuffer array after processing. Result: No more dangling references after done.
This commit is contained in:
parent
a1afaf4c35
commit
5d4e34b021
@ -30,6 +30,7 @@ import io.netty.util.internal.logging.InternalLoggerFactory;
|
|||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.ClosedChannelException;
|
import java.nio.channels.ClosedChannelException;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
|
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
|
||||||
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
|
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
|
||||||
|
|
||||||
@ -245,6 +246,7 @@ public final class ChannelOutboundBuffer {
|
|||||||
public boolean remove() {
|
public boolean remove() {
|
||||||
Entry e = flushedEntry;
|
Entry e = flushedEntry;
|
||||||
if (e == null) {
|
if (e == null) {
|
||||||
|
clearNioBuffers();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Object msg = e.msg;
|
Object msg = e.msg;
|
||||||
@ -279,6 +281,7 @@ public final class ChannelOutboundBuffer {
|
|||||||
private boolean remove0(Throwable cause, boolean notifyWritability) {
|
private boolean remove0(Throwable cause, boolean notifyWritability) {
|
||||||
Entry e = flushedEntry;
|
Entry e = flushedEntry;
|
||||||
if (e == null) {
|
if (e == null) {
|
||||||
|
clearNioBuffers();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Object msg = e.msg;
|
Object msg = e.msg;
|
||||||
@ -345,6 +348,17 @@ public final class ChannelOutboundBuffer {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
clearNioBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear all ByteBuffer from the array so these can be GC'ed.
|
||||||
|
// See https://github.com/netty/netty/issues/3837
|
||||||
|
private void clearNioBuffers() {
|
||||||
|
int count = nioBufferCount;
|
||||||
|
if (count > 0) {
|
||||||
|
nioBufferCount = 0;
|
||||||
|
Arrays.fill(NIO_BUFFERS.get(), 0, count, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -651,6 +665,7 @@ public final class ChannelOutboundBuffer {
|
|||||||
} finally {
|
} finally {
|
||||||
inFail = false;
|
inFail = false;
|
||||||
}
|
}
|
||||||
|
clearNioBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void safeSuccess(ChannelPromise promise) {
|
private static void safeSuccess(ChannelPromise promise) {
|
||||||
|
Loading…
Reference in New Issue
Block a user