Class HtmlPageReference
HtmlPage objects that allows garbage collection under memory pressure.
This class extends SoftReference to provide memory-sensitive caching of HTML pages
in the Oorian framework. When the JVM runs low on memory, the garbage collector may reclaim
softly-referenced pages to free up space. This enables efficient page caching that automatically
adjusts to available memory while maintaining pages as long as possible.
Features:
- Wraps HtmlPage instances in a soft reference
- Allows garbage collection when memory is constrained
- Used by OorianSession for page caching
- Provides automatic memory management for page instances
- Maintains pages in cache as long as memory permits
Usage:
// Store page in a soft reference cache
HtmlPage page = new MyPage();
HtmlPageReference pageRef = new HtmlPageReference(page);
pageCache.put(pageId, pageRef);
// Later, retrieve the page if still available
HtmlPageReference ref = pageCache.get(pageId);
if (ref != null) {
HtmlPage cachedPage = ref.get();
if (cachedPage != null) {
// Use the cached page
} else {
// Page was garbage collected, recreate if needed
}
}
Memory Behavior: The JVM will clear soft references when memory is low, but it tries to keep them as long as possible. This makes soft references ideal for page caching that should be retained when memory is available but can be sacrificed under memory pressure. Pages will be automatically recreated when needed after being cleared.
- Since:
- 2021
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionHtmlPageReference(HtmlPage referent) Constructs a new HtmlPageReference wrapping the specified HTML page. -
Method Summary
Methods inherited from class java.lang.ref.SoftReference
getMethods inherited from class java.lang.ref.Reference
clear, clone, enqueue, isEnqueued, reachabilityFence, refersTo
-
Constructor Details
-
HtmlPageReference
Constructs a new HtmlPageReference wrapping the specified HTML page.The page will be held by a soft reference, allowing it to be garbage collected when the JVM needs to free memory. This is typically used by
OorianSessionto cache page instances while allowing automatic memory management.- Parameters:
referent- the HtmlPage to wrap in a soft reference (must not be null)
-