Add refcounting for structures.

This isn't enough to work for all cases: cycles can be introduced in the
structure graph by function values with arbitrary environment pointers.
That will also need to be fixed.