MemoryRegionCache$Entry objects are not recycled

Motivation:

Even though MemoryRegionCache$Entry instances are allocated through a recycler they are not properly recycled,
leaving a lot of instances to be GCed along with Recycler$DefaultHandle objects.
Fixes #4071

Modification:

Recycle Entry when done using it.

Result:

Less GCed objects.
This commit is contained in:
Matteo Merli 2015-08-07 22:37:51 -07:00 committed by Norman Maurer
parent fd5db7fa08
commit 53f9438aec

View File

@ -386,7 +386,14 @@ final class PoolThreadCache {
*/
@SuppressWarnings("unchecked")
public final boolean add(PoolChunk<T> chunk, long handle) {
return queue.offer(newEntry(chunk, handle));
Entry<T> entry = newEntry(chunk, handle);
boolean queued = queue.offer(entry);
if (!queued) {
// If it was not possible to cache the chunk, immediately recycle the entry
entry.recycle();
}
return queued;
}
/**
@ -398,6 +405,7 @@ final class PoolThreadCache {
return false;
}
initBuf(entry.chunk, entry.handle, buf, reqCapacity);
entry.recycle();
// allocations is not thread-safe which is fine as this is only called from the same thread all time.
++ allocations;