We have been experiencing memory leaks when using pooled memory. The problem resides in NativeBuffer.Pool.create() (along with its interaction with the delete() and release() methods). Consider the case where there are two create() methods called before the corresponding delete()s are called (as is the case in NativeDB.put()) and the total size of the key-value is less than the chunk size (but each of the key and value individually are smaller than the chunk size). It is possible for the first create() to create an allocation (via NativeBuffer.Pool.allocate()) but the second create() to trigger remaining < size and have delete() called.
The memory leak occurs because delete() calls allocation.release() which will not actually release the memory because the NativeBuffer from the first create() still has a reference to it but yet self is set to 0! This means that when the reference counter finally gets to zero that nothing is actually free'd since the pointer (self) isn't pointing to the allocated memory any more.
At this point, I'd wager that the fix is to simply move self = 0 into else if block above where it is now.
We have been experiencing memory leaks when using pooled memory. The problem resides in
NativeBuffer.Pool.create()
(along with its interaction with thedelete()
andrelease()
methods). Consider the case where there are twocreate()
methods called before the correspondingdelete()
s are called (as is the case inNativeDB.put()
) and the total size of the key-value is less than the chunk size (but each of the key and value individually are smaller than the chunk size). It is possible for the firstcreate()
to create an allocation (viaNativeBuffer.Pool.allocate()
) but the secondcreate()
to triggerremaining < size
and havedelete()
called.The memory leak occurs because
delete()
callsallocation.release()
which will not actually release the memory because theNativeBuffer
from the firstcreate()
still has a reference to it but yetself
is set to0
! This means that when the reference counter finally gets to zero that nothing is actually free'd since the pointer (self
) isn't pointing to the allocated memory any more.At this point, I'd wager that the fix is to simply move
self = 0
intoelse if
block above where it is now.