Fixed issue: NETTY-310 Memory leak in netty-3.2.0.BETA1.jar
* Added a special internal use only constructor to AbstractChannel, which bypasses ID allocation * EmbeddedChannel calls the special purpose constructor to avoid leak
This commit is contained in:
parent
93f9c4a2d6
commit
3847fb00e5
@ -59,7 +59,7 @@ public abstract class AbstractChannel implements Channel {
|
||||
}
|
||||
}
|
||||
|
||||
private final Integer id = allocateId(this);
|
||||
private final Integer id;
|
||||
private final Channel parent;
|
||||
private final ChannelFactory factory;
|
||||
private final ChannelPipeline pipeline;
|
||||
@ -90,7 +90,36 @@ public abstract class AbstractChannel implements Channel {
|
||||
this.parent = parent;
|
||||
this.factory = factory;
|
||||
this.pipeline = pipeline;
|
||||
|
||||
id = allocateId(this);
|
||||
closeFuture.addListener(ID_DEALLOCATOR);
|
||||
|
||||
pipeline.attach(this, sink);
|
||||
}
|
||||
|
||||
/**
|
||||
* (Internal use only) Creates a new temporary instance with the specified
|
||||
* ID.
|
||||
*
|
||||
* @param parent
|
||||
* the parent of this channel. {@code null} if there's no parent.
|
||||
* @param factory
|
||||
* the factory which created this channel
|
||||
* @param pipeline
|
||||
* the pipeline which is going to be attached to this channel
|
||||
* @param sink
|
||||
* the sink which will receive downstream events from the pipeline
|
||||
* and send upstream events to the pipeline
|
||||
*/
|
||||
protected AbstractChannel(
|
||||
Integer id,
|
||||
Channel parent, ChannelFactory factory,
|
||||
ChannelPipeline pipeline, ChannelSink sink) {
|
||||
|
||||
this.id = id;
|
||||
this.parent = parent;
|
||||
this.factory = factory;
|
||||
this.pipeline = pipeline;
|
||||
pipeline.attach(this, sink);
|
||||
}
|
||||
|
||||
|
@ -24,18 +24,23 @@ import org.jboss.netty.channel.ChannelSink;
|
||||
import org.jboss.netty.channel.DefaultChannelConfig;
|
||||
|
||||
/**
|
||||
* TODO Make EmbeddedChannel implement ChannelConfig and ChannelSink to reduce overhead.
|
||||
* TODO Do not extend AbstractChannel to reduce overhead and remove the internal-use-only constructor in AbstractChannel.
|
||||
*
|
||||
* @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
|
||||
* @author <a href="http://gleamynode.net/">Trustin Lee</a>
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
class EmbeddedChannel extends AbstractChannel {
|
||||
|
||||
private static final Integer DUMMY_ID = Integer.valueOf(0);
|
||||
|
||||
private final ChannelConfig config;
|
||||
private final SocketAddress localAddress = new EmbeddedSocketAddress();
|
||||
private final SocketAddress remoteAddress = new EmbeddedSocketAddress();
|
||||
|
||||
EmbeddedChannel(ChannelPipeline pipeline, ChannelSink sink) {
|
||||
super(null, EmbeddedChannelFactory.INSTANCE, pipeline, sink);
|
||||
super(DUMMY_ID, null, EmbeddedChannelFactory.INSTANCE, pipeline, sink);
|
||||
config = new DefaultChannelConfig();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user