Manually GC direct ByteBuffer that is used by the Worker's on releaseExternalResources() to free up memory asap. See #638
This commit is contained in:
parent
6ca523a754
commit
a6e89aa142
@ -49,10 +49,11 @@ import org.jboss.netty.channel.socket.Worker;
|
||||
import org.jboss.netty.channel.socket.nio.SocketSendBufferPool.SendBuffer;
|
||||
import org.jboss.netty.logging.InternalLogger;
|
||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
import org.jboss.netty.util.ExternalResourceReleasable;
|
||||
import org.jboss.netty.util.ThreadRenamingRunnable;
|
||||
import org.jboss.netty.util.internal.DeadLockProofWorker;
|
||||
|
||||
abstract class AbstractNioWorker implements Worker {
|
||||
abstract class AbstractNioWorker implements Worker, ExternalResourceReleasable {
|
||||
|
||||
|
||||
private static final AtomicInteger nextId = new AtomicInteger();
|
||||
@ -902,6 +903,11 @@ abstract class AbstractNioWorker implements Worker {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void releaseExternalResources() {
|
||||
sendBufferPool.releaseExternalResources();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read is called when a Selector has been notified that the underlying channel
|
||||
* was something to be read. The channel would previously have registered its interest
|
||||
|
@ -75,6 +75,9 @@ public abstract class AbstractNioWorkerPool<E extends AbstractNioWorker>
|
||||
|
||||
public void releaseExternalResources() {
|
||||
ExecutorUtil.terminate(workerExecutor);
|
||||
for (AbstractNioWorker worker: workers) {
|
||||
worker.releaseExternalResources();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -110,6 +110,12 @@ public class NioDatagramWorker extends AbstractNioWorker {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void releaseExternalResources() {
|
||||
super.releaseExternalResources();
|
||||
bufferAllocator.releaseExternalResources();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean scheduleWriteIfNecessary(final AbstractNioChannel<?> channel) {
|
||||
final Thread workerThread = thread;
|
||||
|
@ -130,6 +130,12 @@ public class NioWorker extends AbstractNioWorker {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseExternalResources() {
|
||||
super.releaseExternalResources();
|
||||
recvBufferPool.releaseExternalResources();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Runnable createRegisterTask(AbstractNioChannel<?> channel, ChannelFuture future) {
|
||||
boolean server = !(channel instanceof NioClientSocketChannel);
|
||||
|
@ -17,9 +17,10 @@ package org.jboss.netty.channel.socket.nio;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.jboss.netty.util.ExternalResourceReleasable;
|
||||
import org.jboss.netty.util.internal.ByteBufferUtil;
|
||||
|
||||
final class SocketReceiveBufferAllocator {
|
||||
final class SocketReceiveBufferAllocator implements ExternalResourceReleasable {
|
||||
|
||||
private ByteBuffer buf;
|
||||
private int exceedCount;
|
||||
@ -72,4 +73,10 @@ final class SocketReceiveBufferAllocator {
|
||||
}
|
||||
return q << 10;
|
||||
}
|
||||
|
||||
public void releaseExternalResources() {
|
||||
if (buf != null) {
|
||||
ByteBufferUtil.destroy(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,8 +27,10 @@ import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.buffer.CompositeChannelBuffer;
|
||||
import org.jboss.netty.channel.DefaultFileRegion;
|
||||
import org.jboss.netty.channel.FileRegion;
|
||||
import org.jboss.netty.util.ExternalResourceReleasable;
|
||||
import org.jboss.netty.util.internal.ByteBufferUtil;
|
||||
|
||||
final class SocketSendBufferPool {
|
||||
final class SocketSendBufferPool implements ExternalResourceReleasable {
|
||||
|
||||
private static final SendBuffer EMPTY_BUFFER = new EmptySendBuffer();
|
||||
|
||||
@ -383,4 +385,10 @@ final class SocketSendBufferPool {
|
||||
// Unpooled.
|
||||
}
|
||||
}
|
||||
|
||||
public void releaseExternalResources() {
|
||||
if (current.buffer != null) {
|
||||
ByteBufferUtil.destroy(current.buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user