/*
 * Copyright 2012 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package io.netty.buffer;

import io.netty.util.internal.PlatformDependent;

/**
 * Simplistic {@link ByteBufAllocator} implementation that does not pool anything.
 */
public final class UnpooledByteBufAllocator extends AbstractByteBufAllocator {

    /**
     * Default instance
     */
    public static final UnpooledByteBufAllocator DEFAULT =
            new UnpooledByteBufAllocator(PlatformDependent.directBufferPreferred());

    /**
     * Create a new instance
     *
     * @param preferDirect {@code true} if {@link #buffer(int)} should try to allocate a direct buffer rather than
     *                     a heap buffer
     */
    public UnpooledByteBufAllocator(boolean preferDirect) {
        super(preferDirect);
    }

    @Override
    protected ByteBuf newHeapBuffer(int initialCapacity, int maxCapacity) {
        return PlatformDependent.hasUnsafe() ? new UnpooledUnsafeHeapByteBuf(this, initialCapacity, maxCapacity)
                : new UnpooledHeapByteBuf(this, initialCapacity, maxCapacity);
    }

    @Override
    protected ByteBuf newDirectBuffer(int initialCapacity, int maxCapacity) {
        ByteBuf buf;
        if (PlatformDependent.hasUnsafe()) {
            buf = new UnpooledUnsafeDirectByteBuf(this, initialCapacity, maxCapacity);
        } else {
            buf = new UnpooledDirectByteBuf(this, initialCapacity, maxCapacity);
        }

        return toLeakAwareBuffer(buf);
    }

    @Override
    public boolean isDirectBufferPooled() {
        return false;
    }
}

@@ -883,35 +883,129 @@
     
-/**%0A     * Default instance
+private final boolean disableLeakDetector;%0A%0A    /**%0A     * Default instance which uses leak-detection for direct buffers.
 %0A   
@@ -1190,16 +1190,62 @@
 instance
+ which uses leak-detection for direct buffers.
 %0A     *%0A
@@ -1480,27 +1480,723 @@
     
-super(preferDirect)
+this(preferDirect, false);%0A    %7D%0A%0A    /**%0A     * Create a new instance%0A     *%0A     * @param preferDirect %7B@code true%7D if %7B@link #buffer(int)%7D should try to allocate a direct buffer rather than%0A     *                     a heap buffer%0A     * @param disableLeakDetector %7B@code true%7D if the leak-detection should be disabled completely for this%0A     *                            allocator. This can be useful if the user just want to depend on the GC to handle%0A     *                            direct buffers when not explicit released.%0A     */%0A    public UnpooledByteBufAllocator(boolean preferDirect, boolean disableLeakDetector) %7B%0A        super(preferDirect);%0A        this.disableLeakDetector = disableLeakDetector
 ;%0A  
@@ -2604,22 +2604,11 @@
  buf
-;%0A        if (
+ = 
 Plat
@@ -2632,19 +2632,18 @@
 Unsafe()
-) %7B
+ ?
 %0A       
@@ -2639,37 +2639,35 @@
 ) ?%0A            
-buf =
+   
  new UnpooledUns
@@ -2710,33 +2710,34 @@
 ty, maxCapacity)
-;
+ :
 %0A        %7D else 
@@ -2733,34 +2733,15 @@
     
-%7D else %7B%0A            buf =
+       
  new
@@ -2800,24 +2800,25 @@
 acity);%0A
+%0A
         
 %7D%0A%0A     
@@ -2813,25 +2813,531 @@
     
-%7D%0A%0A        return
+return disableLeakDetector ? buf : toLeakAwareBuffer(buf);%0A    %7D%0A%0A    @Override%0A    public CompositeByteBuf compositeHeapBuffer(int maxNumComponents) %7B%0A        CompositeByteBuf buf = new CompositeByteBuf(this, false, maxNumComponents);%0A        return disableLeakDetector ? buf : toLeakAwareBuffer(buf);%0A    %7D%0A%0A    @Override%0A    public CompositeByteBuf compositeDirectBuffer(int maxNumComponents) %7B%0A        CompositeByteBuf buf = new CompositeByteBuf(this, true, maxNumComponents);%0A        return disableLeakDetector ? buf :
  toL

Allow to disable leak detection for all buffers when using UnpooledByteBufAllocator.