guides

Memory Management

Understanding how Pyvorin manages memory for native-compiled Python.

Published May 30, 2026

Reference Counting

Pyvorin-compiled code uses CPython's reference counting for object lifetime management. There is no garbage collection pause introduced by compilation.

Stack Allocation

Primitive types (int, float, bool) that are proven local and unescaped may be stack-allocated in optimised builds, reducing heap pressure.

Object Lifetime

Objects created in compiled code follow the same lifetime rules as CPython:

  • Local variables are decref'd on function exit.
  • Returned objects are transferred to the caller.
  • Circular references require the cyclic GC (unchanged).

Memory Leaks

If you suspect a leak in compiled code:

  1. Run the same code in CPython to verify the leak is compiler-specific.
  2. Check for reference cycles with gc.get_referrers().
  3. Report the issue with a minimal reproducer.