diff --git a/codec/src/main/java/io/netty/handler/codec/MessageToMessageCodec.java b/codec/src/main/java/io/netty/handler/codec/MessageToMessageCodec.java index 8f22b7b2e7..ef559a7caa 100644 --- a/codec/src/main/java/io/netty/handler/codec/MessageToMessageCodec.java +++ b/codec/src/main/java/io/netty/handler/codec/MessageToMessageCodec.java @@ -15,6 +15,7 @@ */ package io.netty.handler.codec; +import io.netty.buffer.ReferenceCounted; import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPromise; @@ -45,6 +46,10 @@ import io.netty.util.internal.TypeParameterMatcher; * } * } * + * + * Be aware that you need to call {@link ReferenceCounted#retain()} on messages that are just passed through if they + * are of type {@link ReferenceCounted}. This is needed as the {@link MessageToMessageCodec} will call + * {@link ReferenceCounted#release()} on encoded / decoded messages. */ public abstract class MessageToMessageCodec extends ChannelDuplexHandler { diff --git a/codec/src/main/java/io/netty/handler/codec/MessageToMessageDecoder.java b/codec/src/main/java/io/netty/handler/codec/MessageToMessageDecoder.java index e1851778fb..50d85c9c4d 100644 --- a/codec/src/main/java/io/netty/handler/codec/MessageToMessageDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/MessageToMessageDecoder.java @@ -16,13 +16,15 @@ package io.netty.handler.codec; import io.netty.buffer.ByteBufUtil; +import io.netty.buffer.ReferenceCounted; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.MessageList; import io.netty.util.internal.TypeParameterMatcher; /** - * {@link ChannelInboundHandlerAdapter} which decodes from one message to an other message + * {@link ChannelInboundHandlerAdapter} which decodes from one message to an other message. + * * * For example here is an implementation which decodes a {@link String} to an {@link Integer} which represent * the length of the {@link String}. @@ -39,6 +41,10 @@ import io.netty.util.internal.TypeParameterMatcher; * } * * + * Be aware that you need to call {@link ReferenceCounted#retain()} on messages that are just passed through if they + * are of type {@link ReferenceCounted}. This is needed as the {@link MessageToMessageDecoder} will call + * {@link ReferenceCounted#release()} on decoded messages. + * */ public abstract class MessageToMessageDecoder extends ChannelInboundHandlerAdapter { diff --git a/codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java b/codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java index 8e119f5300..8d5bd6572a 100644 --- a/codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java +++ b/codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java @@ -16,6 +16,7 @@ package io.netty.handler.codec; import io.netty.buffer.ByteBufUtil; +import io.netty.buffer.ReferenceCounted; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelOutboundHandlerAdapter; import io.netty.channel.ChannelPromise; @@ -39,6 +40,9 @@ import io.netty.util.internal.TypeParameterMatcher; * } * * + * Be aware that you need to call {@link ReferenceCounted#retain()} on messages that are just passed through if they + * are of type {@link ReferenceCounted}. This is needed as the {@link MessageToMessageEncoder} will call + * {@link ReferenceCounted#release()} on encoded messages. */ public abstract class MessageToMessageEncoder extends ChannelOutboundHandlerAdapter {