const int CalculateThreshold            = 1048576 * 4; // 4 MiB page

        protected static IByteBuffer ToLeakAwareBuffer(IByteBuffer buf)
        {
            IResourceLeakTracker leak;

            switch (ResourceLeakDetector.Level)
            {
            case ResourceLeakDetector.DetectionLevel.Simple:
                leak = AbstractByteBuffer.LeakDetector.Track(buf);
                if (leak != null)
                {
                    buf = new SimpleLeakAwareByteBuffer(buf, leak);
                }
                break;

            case ResourceLeakDetector.DetectionLevel.Advanced:
            case ResourceLeakDetector.DetectionLevel.Paranoid:
                leak = AbstractByteBuffer.LeakDetector.Track(buf);
                if (leak != null)
                {
                    buf = new AdvancedLeakAwareByteBuffer(buf, leak);
                }
                break;

            case ResourceLeakDetector.DetectionLevel.Disabled:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(buf);
        }
 protected static IByteBuffer ToLeakAwareBuffer(IByteBuffer buf)
 {
     IResourceLeak leak;
     switch (ResourceLeakDetector.Level)
     {
         case ResourceLeakDetector.DetectionLevel.Simple:
             leak = AbstractByteBuffer.LeakDetector.Open(buf);
             if (leak != null)
             {
                 buf = new SimpleLeakAwareByteBuffer(buf, leak);
             }
             break;
         case ResourceLeakDetector.DetectionLevel.Advanced:
         case ResourceLeakDetector.DetectionLevel.Paranoid:
             leak = AbstractByteBuffer.LeakDetector.Open(buf);
             if (leak != null)
             {
                 buf = new AdvancedLeakAwareByteBuffer(buf, leak);
             }
             break;
         case ResourceLeakDetector.DetectionLevel.Disabled:
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
     return buf;
 }