public class MemoryManager extends java.lang.Object
It can be used to hold imagery caches or other data that can be reconstructed form disk/web if required.
Reclaimable storage implementations may be added in the future.
Modifier and Type | Class and Description |
---|---|
private class |
MemoryManager.ManualFreeMemoryHandle<T> |
static interface |
MemoryManager.MemoryHandle<T>
A memory area managed by the
MemoryManager . |
static class |
MemoryManager.NotEnoughMemoryException
This exception is thrown if there is not enough memory for allocating the given object.
|
Modifier and Type | Field and Description |
---|---|
private java.util.ArrayList<MemoryManager.MemoryHandle<?>> |
activeHandles |
private static MemoryManager |
INSTANCE |
private static long |
JOSM_CORE_FOOTPRINT
assumed minimum JOSM memory footprint
|
Modifier | Constructor and Description |
---|---|
protected |
MemoryManager() |
Modifier and Type | Method and Description |
---|---|
<T> MemoryManager.MemoryHandle<T> |
allocateMemory(java.lang.String name,
long maxBytes,
java.util.function.Supplier<T> factory)
Allocates a basic, fixed memory size.
|
long |
getAvailableMemory()
Gets the memory that is considered free.
|
static MemoryManager |
getInstance()
Get the global memory manager instance.
|
long |
getMaxMemory()
Gets the maximum amount of memory available for use in this manager.
|
boolean |
isAvailable(long maxBytes)
Check if that memory is available
|
protected java.util.List<MemoryManager.MemoryHandle<?>> |
resetState()
Reset the state of this manager to the default state.
|
private static final long JOSM_CORE_FOOTPRINT
private static final MemoryManager INSTANCE
private final java.util.ArrayList<MemoryManager.MemoryHandle<?>> activeHandles
protected MemoryManager()
public <T> MemoryManager.MemoryHandle<T> allocateMemory(java.lang.String name, long maxBytes, java.util.function.Supplier<T> factory) throws MemoryManager.NotEnoughMemoryException
If there is enough free memory, the factory is used to procude one element which is then returned as memory handle.
You should invoke MemoryManager.MemoryHandle.free()
if you do not need that handle any more.
T
- The content type of the memory-name
- A name for the memory area. Only used for debugging.maxBytes
- The maximum amount of bytes the content may havefactory
- The factory to use to procude the content if there is sufficient memory.MemoryManager.NotEnoughMemoryException
- If there is not enough memory to allocate.public boolean isAvailable(long maxBytes)
maxBytes
- The memory to check fortrue
if that memory is available.public long getMaxMemory()
public long getAvailableMemory()
public static MemoryManager getInstance()
protected java.util.List<MemoryManager.MemoryHandle<?>> resetState()