0
次のテストではPooledByteBufAllocatorアリーナの番号が出力されます。実行すると、実際の割り当て/割り当て解除と一致しません。 実際の配分:50000の 実際の割り当て解除:50000 アクティブバッファ:0Netty 4 PooledByteBufAllocatorが割り当て/割り当て解除に関する不正な情報を返します
出力は、以下を示す: directActive 1 directAlloc 1 directDealloc 0 heapActive 0ます。HeapAlloc 0 heapDealloc 0
import io.netty.buffer.ByteBuf;
import io.netty.buffer.PoolArenaMetric;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.util.ResourceLeakDetector;
import io.netty.util.ResourceLeakDetector.Level;
import org.junit.Test;
public class NettyTest2 {
public static PooledByteBufAllocator alloc = new PooledByteBufAllocator(true);
@Test
public void test() throws InterruptedException {
ResourceLeakDetector.setLevel(Level.PARANOID);
for (int i = 0; i < 50000; i++) {
ByteBuf b = alloc.buffer(1000, 1000);
b.release();
}
Thread.sleep(100);
//alloc.freeThreadLocalCache();
showActiveDirectBuffers();
showActiveHeapBuffers();
}
void showActiveDirectBuffers() {
int directActive = 0, directAlloc = 0, directDealloc = 0;
for (PoolArenaMetric arena : alloc.directArenas()) {
directActive += arena.numActiveAllocations();
directAlloc += arena.numAllocations();
directDealloc += arena.numDeallocations();
}
System.out.println("directActive " + directActive + " directAlloc " + directAlloc + " directDealloc " + directDealloc);
}
void showActiveHeapBuffers() {
int heapActive = 0, heapAlloc = 0, heapDealloc = 0;
for (PoolArenaMetric arena : alloc.heapArenas()) {
heapActive += arena.numActiveAllocations();
heapAlloc += arena.numAllocations();
heapDealloc += arena.numDeallocations();
}
System.out.println("heapActive " + heapActive + " heapAlloc " + heapAlloc + " heapDealloc " + heapDealloc);
}
}