# LossyRef, better than WeakRef

**URL:** <https://es.discourse.group/t/lossyref-better-than-weakref/1096>\
**Category:** 💡 Ideas\
**Created:** [November 17, 2021, 6:00pm UTC](https://es.discourse.group/t/lossyref-better-than-weakref/1096 "2021-11-17T18:00:50Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![trusktr](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/trusktr/32/183_2.png) [@trusktr](https://es.discourse.group/u/trusktr)\
**Post date:** [December 30, 2021, 11:53pm UTC](https://es.discourse.group/t/lossyref-better-than-weakref/1096/7 "2021-12-30T23:53:42Z")

</div>

> [@mhofman](#):
>
> Derefing a weakref during that window will not rematerialize the object.

There are two time windows:

1. Between the moment when the user code dropped its last reference to an object and when GC happens, and
2. what you described: between when GC happens and when a FinalizaationRegistry callback happens.

Isn't it possible that before GC happens, inside of the the first time window, that a user can dereference a `WeakRef` and regain a reference back to an object, therefore preventing GC of the object and hence preventing the FinalizationRegistry callback, and that if a user loses and always re-gains an object reference in this manner before GC has a chance to run, that they will never collect the object?

Isn't that the problem that [How to implement TwoWayWeakMap? Using WeakRef?](https://es.discourse.group/t/how-to-implement-twowayweakmap-using-weakref/890) has shown?

Let me know if you need me to show both the working and leaky examples here.

---

_[View the full topic](https://es.discourse.group/t/lossyref-better-than-weakref/1096)._
