Package org.openstreetmap.josm.tools
Class MemoryManager
- java.lang.Object
-
- org.openstreetmap.josm.tools.MemoryManager
-
public class MemoryManager extends java.lang.Object
This class allows all components of JOSM to register reclaimable amounts to memory.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.
- Since:
- 10588
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
MemoryManager.ManualFreeMemoryHandle<T>
static interface
MemoryManager.MemoryHandle<T>
A memory area managed by theMemoryManager
.static class
MemoryManager.NotEnoughMemoryException
This exception is thrown if there is not enough memory for allocating the given object.
-
Field Summary
Fields Modifier and Type Field Description private java.util.ArrayList<MemoryManager.MemoryHandle<?>>
activeHandles
private static MemoryManager
INSTANCE
private static long
JOSM_CORE_FOOTPRINT
assumed minimum JOSM memory footprint
-
Constructor Summary
Constructors Modifier Constructor Description protected
MemoryManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 availableprotected java.util.List<MemoryManager.MemoryHandle<?>>
resetState()
Reset the state of this manager to the default state.
-
-
-
Field Detail
-
JOSM_CORE_FOOTPRINT
private static final long JOSM_CORE_FOOTPRINT
assumed minimum JOSM memory footprint- See Also:
- Constant Field Values
-
INSTANCE
private static final MemoryManager INSTANCE
-
activeHandles
private final java.util.ArrayList<MemoryManager.MemoryHandle<?>> activeHandles
-
-
Constructor Detail
-
MemoryManager
protected MemoryManager()
-
-
Method Detail
-
allocateMemory
public <T> MemoryManager.MemoryHandle<T> allocateMemory(java.lang.String name, long maxBytes, java.util.function.Supplier<T> factory) throws MemoryManager.NotEnoughMemoryException
Allocates a basic, fixed memory size.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.- Type Parameters:
T
- The content type of the memory-- Parameters:
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.- Returns:
- A memory handle to the content.
- Throws:
MemoryManager.NotEnoughMemoryException
- If there is not enough memory to allocate.
-
isAvailable
public boolean isAvailable(long maxBytes)
Check if that memory is available- Parameters:
maxBytes
- The memory to check for- Returns:
true
if that memory is available.
-
getMaxMemory
public long getMaxMemory()
Gets the maximum amount of memory available for use in this manager.- Returns:
- The maximum amount of memory.
-
getAvailableMemory
public long getAvailableMemory()
Gets the memory that is considered free.- Returns:
- The memory that can be used for new allocations.
-
getInstance
public static MemoryManager getInstance()
Get the global memory manager instance.- Returns:
- The memory manager.
-
resetState
protected java.util.List<MemoryManager.MemoryHandle<?>> resetState()
Reset the state of this manager to the default state.- Returns:
- true if there were entries that have been reset.
-
-