title: Netty 4.0 ByteBuf retain() use
body: <p>I'm trying understand decode aTrack protocol based on <a href="https://github.com/traccar/traccar" rel="nofollow noreferrer">https://github.com/traccar/traccar</a> implementation, they use Netty for their platform implementation, but I don't underestand which is the use of the retain method of ByteBuf's object. They used it in this method:</p>
  
  <pre><code>protected Object decode(
          Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
  
      ByteBuf buf = (ByteBuf) msg;
  
      if (buf.getUnsignedShort(buf.readerIndex()) == 0xfe02) {
          if (channel != null) {
              channel.writeAndFlush(new NetworkMessage(buf.retain(), remoteAddress)); // keep-alive message
          }
          return null;
      } else if (buf.getByte(buf.readerIndex()) == '$') {
          return decodeInfo(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII).trim());
      } else if (buf.getByte(buf.readerIndex() + 2) == ',') {
          return decodeText(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII).trim());
      } else {
          return decodeBinary(channel, remoteAddress, buf);
      }
  }
  </code></pre>
  
  <h2><strong>Someone could explain me how works ByteBuf retain() method?</strong></h2>
  
  <p>thanks.</p>