Fix dangling pointers.

CDocument is now refcounted, too. We can't keep references to objects that are directly in a vector, because a vector re-allocates its objects when you add one.