Also allow to override how direct ByteBuffers are freed

This commit is contained in:
Norman Maurer 2013-11-12 12:40:41 +01:00
parent e83fb821d5
commit 7231be592a
2 changed files with 18 additions and 4 deletions

View File

@ -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) {

View File

@ -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) {