WeakLazy
A lazily computed value cached through a WeakRef, so the cached instance can be garbage collected and recomputed later.
Reading value runs the initializer on first access and whenever the previously cached instance has been collected, so the initializer may run more than once and must be pure enough to tolerate that. Between collections, reads return the same instance. This makes WeakLazy a fit for expensive-to-build but reconstructible objects such as parsed resources, caches, or renderers.
On targets where WeakRef.isWeakSupported is false (Kotlin/Wasm, and JS runtimes without ES2021 WeakRef) the cached instance is held strongly and is never collected, so after the first read this behaves like a plain lazy, although refresh and clear still replace or drop the cache.
This class is not thread-safe. Concurrent reads may each run the initializer and observe different instances; confine an instance to one thread or add external synchronization.
val table = weakLazy { loadHyphenationTable() }
table.value.hyphenate(word) // recomputed transparently if collected