Also allow to override how direct ByteBuffers are freed
This commit is contained in:
parent
9b7d286652
commit
d11d3a6b50
@ -109,13 +109,20 @@ public class UnpooledDirectByteBuf extends AbstractReferenceCountedByteBuf {
|
||||
return ByteBuffer.allocateDirect(initialCapacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Free a direct {@link ByteBuffer}
|
||||
*/
|
||||
protected void freeDirect(ByteBuffer buffer) {
|
||||
PlatformDependent.freeDirectBuffer(buffer);
|
||||
}
|
||||
|
||||
private void setByteBuffer(ByteBuffer buffer) {
|
||||
ByteBuffer oldBuffer = this.buffer;
|
||||
if (oldBuffer != null) {
|
||||
if (doNotFree) {
|
||||
doNotFree = false;
|
||||
} else {
|
||||
PlatformDependent.freeDirectBuffer(oldBuffer);
|
||||
freeDirect(oldBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -595,7 +602,7 @@ public class UnpooledDirectByteBuf extends AbstractReferenceCountedByteBuf {
|
||||
this.buffer = null;
|
||||
|
||||
if (!doNotFree) {
|
||||
PlatformDependent.freeDirectBuffer(buffer);
|
||||
freeDirect(buffer);
|
||||
}
|
||||
|
||||
if (leak != null) {
|
||||
|
@ -112,13 +112,20 @@ public class UnpooledUnsafeDirectByteBuf extends AbstractReferenceCountedByteBuf
|
||||
return ByteBuffer.allocateDirect(initialCapacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Free a direct {@link ByteBuffer}
|
||||
*/
|
||||
protected void freeDirect(ByteBuffer buffer) {
|
||||
PlatformDependent.freeDirectBuffer(buffer);
|
||||
}
|
||||
|
||||
private void setByteBuffer(ByteBuffer buffer) {
|
||||
ByteBuffer oldBuffer = this.buffer;
|
||||
if (oldBuffer != null) {
|
||||
if (doNotFree) {
|
||||
doNotFree = false;
|
||||
} else {
|
||||
PlatformDependent.freeDirectBuffer(oldBuffer);
|
||||
freeDirect(oldBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -495,7 +502,7 @@ public class UnpooledUnsafeDirectByteBuf extends AbstractReferenceCountedByteBuf
|
||||
this.buffer = null;
|
||||
|
||||
if (!doNotFree) {
|
||||
PlatformDependent.freeDirectBuffer(buffer);
|
||||
freeDirect(buffer);
|
||||
}
|
||||
|
||||
if (leak != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user