3 ms·
Alternative: on substring, reference the original string through a SoftReference registered with a global ReferenceQueue. Have one global system thread poll tha
by VanillaCafe 13y ago
Alternative: on substring, reference the original string through a SoftReference registered with a global ReferenceQueue. Have one global system thread poll that reference queue and to convert substrings to hard copies (requiring a reverse map from the parent to its children via WeakReference) when the parent is about to be collected.
Problem is this is still reasonably complicated (though much less so than the article). A lot of memory churn and possible OOMEs will occur at the time of GC instead of the time of substring allocation. That makes the overall system less predictable and less debuggable, as will any deferred substring reallocation.