weakref is useful to hold a
Reference object without contributing to its refcount.
is_instance_valid only checks if an object is valid.
You cannot only rely on
is_instance_valid in the first case because in the case of
Reference classes your variable would contribute to the refcount. So you'd need to store the object ID instead, which needs to be looked up each time you want the actual object, and that's what
weakref is a wrapper for.