Avoided memory leaks by retaining a weak reference of the target object