D6631: rust-cpython: add macro for sharing references
gracinet (Georges Racinet)
phabricator at mercurial-scm.org
Tue Jul 16 08:51:55 EDT 2019
gracinet added inline comments.
> kevincox wrote in macros.rs:61
> I'm failing to see what actually prevents the "container" from being dropped while the "iterator" is alive. Is this somehow tied to the Python GC?
> For example:
> c = RustObject()
> i = iter(i)
> del c
> # What is keeping the backing rust memory alive at this point.
all that CPython's `del` does is decrement the reference count, and if it drops to 0, then the memory will be freed immediately. On the other hand, the `clone_ref()` at line 106 does increment it.
So, in your example, after `del c` the refcount of `c` is 1 and the memory shouldn't be freed.
CHANGES SINCE LAST ACTION
To: Alphare, #hg-reviewers
Cc: gracinet, durin42, kevincox, mercurial-devel
More information about the Mercurial-devel