From: Charles Oliver Nutter Date: 2013-02-08T13:42:21+09:00 Subject: Re: Soft object reference for mark and sweep On Sun, Jan 27, 2013 at 8:21 AM, Garthy D wrote: > The WeakRef interface worries me though. You'd normally expect to see just > one call on such a thing (lock, which turns weak to strong/fail) and maybe a > check call, with a big warning that the result might change post-check. A > delegation-style interface with a check only seems a bit unusual. However, I > may just not have a proper understanding of how it works yet. I strongly discourage using WeakRef for its delegate interface. It's a terrible pattern that simply needs to go away. If you use WeakRef, just use it as a weak object holder and always check for nil on the return value. You should be ok. You might also check out the "weakling" gem, which provides some other nice features from JVM like reference queues, where your WeakRefs get inserted as their references get collected. It's a bit more efficient (or at least doesn't impact GC performance) than using finalizers. - Charlie