I wish objects wrapped in a WeakReference instance lived longer than they currently do. To fulfil the promise of a WeakReference object to be useful as a cache for the target object, the target should not go away with the first GC - see example below.
We might protect WeakReference targets until a real memory allocation fails, or we might give the WeakReference class an indication of how large a memory workspace is acceptable before WeakReference objects become eligible to be removed.
use strict arg n = 2500 a = .Array~new(n) do i = 1 to a~size a[i] = .WeakReference~new(.DateTime~new) end available = 0 do i = 1 to a~size available += a[i]~value \== .nil end -- on my system: 750 / 2500 weak references still available say available "/" a~size "weak references still available"
Anonymous