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:
parent
fd5db7fa08
commit
53f9438aec
@ -386,7 +386,14 @@ final class PoolThreadCache {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public final boolean add(PoolChunk<T> chunk, long handle) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
initBuf(entry.chunk, entry.handle, buf, reqCapacity);
|
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 is not thread-safe which is fine as this is only called from the same thread all time.
|
||||||
++ allocations;
|
++ allocations;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user