Fix cyclic garbage created by use of WeakRef; add some WeakRef tests.

Fixes issue #95.