Allow the garbage collection of a model's state EntityVar.

This changes uses weak reference for a model's shared entity manager.
If this manager is about to be garbage collected then its finalize
method ensures that the model's state EntityVar is disposed.

Change-Id: If536f68702bb75fe0bd95463083929c9387c1931