public class ReferenceCountingAllocator<T extends Recyclable> extends Object implements Allocator<T>
Allocator
that uses reference counting to determine when an object
should
be recycled and placed back into the pool to be reused.Constructor and Description |
---|
ReferenceCountingAllocator(int initialSize,
Supplier<T> factory) |
ReferenceCountingAllocator(Supplier<T> factory) |
Modifier and Type | Method and Description |
---|---|
Reference<T> |
allocate()
Allocate an object from the internal pool.
|
List<Reference<T>> |
allocateBatch(int size)
Allocate a batch of objects all at once.
|
void |
release(List<Reference<T>> batch)
Efficiently release a batch of References all at once.
|
public Reference<T> allocate()
Allocator
allocate
in interface Allocator<T extends Recyclable>
Reference
that can be retained and released.public List<Reference<T>> allocateBatch(int size)
Allocator
allocateBatch
in interface Allocator<T extends Recyclable>
size
- the number of objects to allocateList
of References
to the allocated objectsCopyright © 2017. All rights reserved.