Github user suyanNone commented on the pull request:

    https://github.com/apache/spark/pull/6586#issuecomment-112055404
  
    and I also think it may be more better to de-allocate direct Buffer while 
we send chunkFetchSuccess to requester.
    I not sure I right or not, 
    NioManagedBuffer ------(convertToNetty)----> Unpool.Wrapper(ByteBuffer)
    Use Unpool.wrapper(), will set doNotFree Flag as true, so it will not free 
the byteBuffer in Netty, It need we to release in user context.
    
    ```
    TransportRequestHandler.java
    
    private void respond(final Encodable result) {
        final String remoteAddress = channel.remoteAddress().toString();
        channel.writeAndFlush(result).addListener(
          new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) throws 
Exception {
              if (future.isSuccess()) {
                logger.trace(String.format("Sent result %s to client %s", 
result, remoteAddress));
                if (result instanceof ChunkFetchSuccess) {
                  ChunkFetchSuccess success = (ChunkFetchSuccess)result;
                  if (success.buffer instanceof NioManagedBuffer) {
                    
JavaUtils.deallocateDirectBuffer(((ChunkFetchSuccess)result).buffer.nioByteBuffer());
                  }
                }
    ```
    
    ```
    JavaUtil.java
      public static void deallocateDirectBuffer(ByteBuffer buffer) {
        if (buffer != null && buffer instanceof MappedByteBuffer) {
          logger.trace("Unmapping " + buffer);
          if (((DirectBuffer)buffer).cleaner() != null ) {
            ((DirectBuffer)buffer).cleaner().clean();
          }
        }
      }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to