Class 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
    • 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 have
        factory - 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.