MANAGED_OBJECT
- public class ObjectManager<MANAGED_OBJECT> extends Object
Implementation is using soft references therefore you don't have to worry about memory leakage - if JVM will need more memory it will purge those soft references.
Note that the manager is thread-safe + get() will always return you an old (or possibly) new instance of the object.
We discourage you to use ObjectManager for objects that have multiple references throughout your code as it is hard to know whether the object is not referenced from other parts of your code so you can give it back to the manager.
Constructor and Description |
---|
ObjectManager(IObjectFactory<MANAGED_OBJECT> objectFactory) |
ObjectManager(IObjectFactory<MANAGED_OBJECT> objectFactory,
int initialObjectCount) |
ObjectManager(IObjectFactory<MANAGED_OBJECT> objectFactory,
int initialObjectCount,
int moreNewObjectsCount) |
Modifier and Type | Method and Description |
---|---|
MANAGED_OBJECT |
get()
Returns you an instance of object.
|
void |
giveBack(MANAGED_OBJECT obj)
Returns an instance of object to the manager, it will be stored in the manager
via soft reference.
|
public ObjectManager(IObjectFactory<MANAGED_OBJECT> objectFactory)
public ObjectManager(IObjectFactory<MANAGED_OBJECT> objectFactory, int initialObjectCount)
objectFactory
- initialObjectCount
- how many objects to create in advancepublic ObjectManager(IObjectFactory<MANAGED_OBJECT> objectFactory, int initialObjectCount, int moreNewObjectsCount)
objectFactory
- initialObjectCount
- how many objects to create in advancemoreNewObjectsCount
- how many new objects to create in advance in case of shortage of free objectspublic MANAGED_OBJECT get()
public void giveBack(MANAGED_OBJECT obj)
obj
- Copyright © 2012 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.