Class SafeAllocator

  • All Implemented Interfaces:
    io.netty.buffer.ByteBufAllocator, io.netty.buffer.ByteBufAllocatorMetricProvider

    public class SafeAllocator
    extends io.netty.buffer.AbstractByteBufAllocator
    implements io.netty.buffer.ByteBufAllocatorMetricProvider
    An instance of SafeAllocator may be used to wrap an existing ByteBufAllocator to provide insurance against slow memory leaks from exceptional conditions by providing a means for the leaked ByteBuf objects to be reclaimed. Makes use of a reference queue per thread in order to avoid some of the synchronization costs.
    • Constructor Summary

      Constructor Description
      SafeAllocator​(io.netty.buffer.ByteBufAllocator allocator)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean isDirectBufferPooled()  
      SafeAllocatorMetric metric()  
      protected io.netty.buffer.ByteBuf newDirectBuffer​(int initialCapacity, int maxCapacity)  
      protected io.netty.buffer.ByteBuf newHeapBuffer​(int initialCapacity, int maxCapacity)  
      protected void reportLeak​(java.lang.String message, int capacity, io.netty.buffer.ByteBuf buf, java.lang.Object hint)  
      java.lang.String toString()  
      • Methods inherited from class io.netty.buffer.AbstractByteBufAllocator

        buffer, buffer, buffer, calculateNewCapacity, compositeBuffer, compositeBuffer, compositeDirectBuffer, compositeDirectBuffer, compositeHeapBuffer, compositeHeapBuffer, directBuffer, directBuffer, directBuffer, heapBuffer, heapBuffer, heapBuffer, ioBuffer, ioBuffer, ioBuffer, toLeakAwareBuffer, toLeakAwareBuffer
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail


        public static final SafeAllocator POOLED_ALLOCATOR

        public static final SafeAllocator UNPOOLED_ALLOCATOR
    • Constructor Detail

      • SafeAllocator

        public SafeAllocator​(@Nonnull
                             io.netty.buffer.ByteBufAllocator allocator)
    • Method Detail

      • newHeapBuffer

        protected final io.netty.buffer.ByteBuf newHeapBuffer​(int initialCapacity,
                                                              int maxCapacity)
        Specified by:
        newHeapBuffer in class io.netty.buffer.AbstractByteBufAllocator
      • newDirectBuffer

        protected final io.netty.buffer.ByteBuf newDirectBuffer​(int initialCapacity,
                                                                int maxCapacity)
        Specified by:
        newDirectBuffer in class io.netty.buffer.AbstractByteBufAllocator
      • isDirectBufferPooled

        public final boolean isDirectBufferPooled()
        Specified by:
        isDirectBufferPooled in interface io.netty.buffer.ByteBufAllocator
      • metric

        public SafeAllocatorMetric metric()
        Specified by:
        metric in interface io.netty.buffer.ByteBufAllocatorMetricProvider
      • reportLeak

        protected void reportLeak​(java.lang.String message,
                                  int capacity,
                                  io.netty.buffer.ByteBuf buf,
                                  java.lang.Object hint)
      • toString

        public java.lang.String toString()
        toString in class io.netty.buffer.AbstractByteBufAllocator