Package org.graffiti.editor
Interface MemoryHog
- All Known Implementing Classes:
EnzymeService
public interface MemoryHog
Memory hogs can be classes that tend to gather a noticeable set of resources, that due to being still referenced, cannot be taken care of by the GC and must be released explicitly from memory. Therefore to allow such deallocation and improve memory performance by preventing memory leaks and overheads for data structures (e.g. expansion of maps or lists). A typical example would be a service, which has to perform some pooling on a given time interval.
- Version:
- v2.0: refactored as interface.
- Author:
- Klukas, D. Garkov
- Recent revisions:
- 2.7.0
-
Field Summary
Fields Modifier and Type Field Description static long[]
lastUsageTime
We use an array as wrapper to access the static value in a non-static method. -
Method Summary
Modifier and Type Method Description default boolean
doFreeMemory()
default void
enablePeriodicFreeMemory()
It sets up a Timer that would free memory after 1 minute passes by continuously during the life of the application.void
freeMemory()
To release a data structure, just re-instantiate it, and GC would collect the now unreachable object some time in the future.default void
noteRequest()
default void
registerMemoryHog()
To enable free-up on application clear memory event, when the user requests such, the hog has to be registered beforehand.
-
Field Details
-
lastUsageTime
static final long[] lastUsageTimeWe use an array as wrapper to access the static value in a non-static method. Do not set explicitly, usenoteRequest()
to set.
-
-
Method Details
-
registerMemoryHog
default void registerMemoryHog()To enable free-up on application clear memory event, when the user requests such, the hog has to be registered beforehand. -
enablePeriodicFreeMemory
default void enablePeriodicFreeMemory()It sets up a Timer that would free memory after 1 minute passes by continuously during the life of the application. The Timer's delay shouldn't be too small, as it could lead to excessive reallocation and memory overheads. -
doFreeMemory
default boolean doFreeMemory() -
noteRequest
default void noteRequest() -
freeMemory
void freeMemory()To release a data structure, just re-instantiate it, and GC would collect the now unreachable object some time in the future.
Apart for deallocation purposes, it can also be used to reset any other dependencies.
-