Skip to content
dreamcode
dreamcode
Map
Python Internals
Lesson 66 of 77
+15 XP on finish
PYTHON EXPERTChapter 11 · Python Expert

Bytecode, GIL, and memory management

CPython compiles source code to bytecode (.pyc) executed by the virtual machine. Memory is managed via reference counting and a cyclic garbage collector, thread-locked by the Global Interpreter Lock.

Worked example

How it reads

  • sys.getrefcount(...) returns references pointing to the object
  • CPython's GIL prevents multiple native threads from executing bytecodes at once
Cloud tip: Reference counting deletes objects immediately when count drops to 0; cycle GC handles self-referencing loops.
main.py
PYTHON
real Python, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Show that b is the same list as a: append 3 to b, then print a ([1, 2, 3]) and a is b (True).

Press Run to check your work.