image

Say you have a method that takes an optional callback.

Maybe you're making one of those classes that says "I'll let you know when some event happens".

Right now, you'll also need to make a way to delete reference to the callback so that the caller (let's call it object A) can GC.

With WeakRef, none of that dance is necessary, just register the callback and then object A can get deleted at any time!

Think of classes that give you registerCallback and deregisterCallback and you need to call deregister on component unload. Now there will not be a need to do that