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.

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.

Hi Kevin,

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.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6631/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6631

To: Alphare, #hg-reviewers
Cc: gracinet, durin42, kevincox, mercurial-devel


More information about the Mercurial-devel mailing list