Any way to figure out if a WeakRef is referenced elsewhere?

If I have a WeakRef to an object, is there any more efficient way to figure out if its referenced elsewhere, other than just running a GC.gc() and checking if my WeakRef value has become nothing?

No. That I formation can only be computed during GC.

Thanks, fair enough. Could you possibly explain what the full argument to GC.gc does? I can’t really find much documentation, but it certainly makes things much faster and alleviates some of why I asked my question in the first place. But its not clear what a non-full GC might miss?

Non full GC ignores old objects, I.e. objects that have lived for a long time (lived many collections). This is based on the assumptions that young objects dies fast. Search generational GC to learn more.

1 Like