More tests
Fix memory leak by using weakref

Use weakref for child-parent relationships to avoid reference cycles