monty 0.0.21

A sandboxed, snapshotable Python interpreter written in Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Mutual reference cycle: a contains b, b contains a
# This creates a cycle where:
#   - a has refcount 2 (variable 'a' + being inside b)
#   - b has refcount 2 (variable 'b' + being inside a)
# Without cycle detection, when both variables go out of scope:
#   - a's refcount drops to 1 (still in b)
#   - b's refcount drops to 1 (still in a)
#   - Neither reaches 0, neither is freed (memory leak)
#
# NOTE: We return len(b) instead of b because repr(b) would cause infinite
# recursion / stack overflow (a separate bug - Python handles this by printing [...]
# for cyclic references)
a = []
b = []
a.append(b)
b.append(a)
len(b)
# ref-counts={'a': 2, 'b': 2}