PooledByteBuf分配及回收之一PooledByteBufAllocator初始化

  • Post author:
  • Post category:其他



PooledByteBufAllocator初始化


PoolThreadCache初始化


PoolAerna初始化


PoolChunk初始化


PoolSubpage初始化


PooledUnsafeDirectByteBuf初始化


分配微小型PooledByteBuf(未命中缓存场景)


分配小型PooledByteBuf(未命中缓存场景)


分配普通型PooledByteBuf(未命中缓存场景)


PoolChunkList源码解析


ReferenceCountUpdater源码解析


Recycler及基内部类初始化


Recycler.Stack<T> 压入对象


Recycler.Stack<T> 弹出对象


PooledByteBuf的回收

接口ByteBufAllocator中定义了一个默认的ByteBufAllocator DEFAULT =

ByteBufUtil.DEFAULT_ALLOCATOR,跟进去:

static final ByteBufAllocator DEFAULT_ALLOCATOR;

static {
    //非安卓返回pooled
    String allocType = SystemPropertyUtil.get(
            "io.netty.allocator.type", PlatformDependent.isAndroid() ? "unpooled" : "pooled");
    allocType = allocType.toLowerCase(Locale.US).trim();

    ByteBufAllocator alloc;
    if ("unpooled".equals(allocType)) {
        alloc = UnpooledByteBufAllocator.DEFAULT;
    } else if ("pooled".equals(allocType)) {
        //到这里
        alloc = PooledByteBufAllocator.DEFAULT;
    } else {
        alloc = PooledByteBufAllocator.DEFAULT;
    }
    //定义DEFAULT_ALLOCATOR = PooledByteBufAllocator.DEFAULT; 跟进去
    DEFAULT_ALLOCATOR = alloc;

在这里 ByteBufAllocator DEFAULT =



版权声明:本文为AnY11原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。