tenderlove/psych — pull request #199 by mjtko (2014-08-06 15:55:41+00:00)
Title: GC can break an ongoing serialization

The YAML serializer makes use of `object_id` to determine whether a `target` object has already been encountered and allow use of an anchor rather than inlining the whole object again. However, this breaks down if GC has collected the original `target` during the course of serialization (as `object_id` is only unique for active objects).

This patch retains a reference to the `target` so GC can't sweep it away.

(I did consider doing something with `Object#hash` in order to try and keep the memory footprint low, but I don't think that's a sane approach as multiple objects can have the same `hash` etc...)