Browse by Topic

Popular

Latest

Latest Posts

Illustration of a Python object held by a solid strong reference and a translucent weak reference that fades away, showing the object can be garbage collected.
Python

Python Weak References: Track Objects Without Blocking Cleanup

Python weak references let you track and cache objects without keeping them alive. Learn how to use weakref.ref, WeakValueDictionary, WeakKeyDictionary, WeakSet, and weakref.finalize with practical examples.

weakrefgarbage collectionmemory managementcaching
Diagram showing a Python del statement removing a reference while the garbage collector handles cyclic references.
Python

Python del vs Garbage Collection: The Real Difference

Understand the difference between Python's del statement and garbage collection in CPython, including reference counting and how cyclic references are handled.

Pythonmemory managementgarbage collectiondel statement
Diagram illustrating Python's garbage collection process with reference counting and cyclic reference detection.
Python

Python Garbage Collection: How It Works

Python garbage collection in CPython combines reference counting with a cyclic collector. Learn how cycles are found, how the gc module's generations and thresholds can be tuned, and how to debug memory leaks.

garbage collectionmemory managementgc modulereference counting
Diagram showing reference counting with arrows between objects and a cycle broken by a weak reference.
Python

How Python Reference Counting Manages Memory

Explore how CPython uses reference counting to free objects, why reference cycles leak, and how to use weakref and the gc module to manage memory.

memory managementgarbage collectionweakrefCPython
Illustration of Python variables as arrows pointing to objects in memory, showing reference sharing and copying.
Python

Understanding Python Object References

python object references: Learn how Python variables store references, how mutability affects assignment and copying, and how to avoid common reference pitfalls.

pythonreferencesmutabilitycopy
Diagram showing multiple Python variables referencing the same object in memory
Python

Understanding Python Memory References and Object Identity

python memory references: Learn how Python variables act as references to objects, how assignment and copying work, and how to avoid common memory-related pitfalls.

pythonmemory referencesobject identityshallow copy
A visual metaphor showing a mutable list being rejected as a dictionary key, with a lock and hash symbol
Python

Why Python Mutable Objects Are Unhashable

python mutable objects unhashable: Understand why mutable objects are unhashable in Python, how the TypeError arises, and practical ways to work around it.

pythonhashingmutable objectsdictionaries
Illustration of a Python dictionary key with a balanced scale between hash and equality, symbolizing the hash equality contract.
Python

Understanding Python's Hash and Equality Contract

Learn how Python's hash and equality methods must stay consistent, why violations break dict and set behavior, and how to implement hashable classes safely.

__hash____eq__hashablepython-dictionaries
Diagram showing hashable objects mapping to hash buckets in a Python dictionary
Python

Python Hashable Objects: Implementation Guide

python hashable objects: Understand what makes Python objects hashable, how to implement __hash__ and __eq__, and avoid common pitfalls with dict and set usage.

hashablepython__hash____eq__
Illustration of two Python objects being compared with == and is, showing value equality versus identity.
Python

Python Object Equality: == vs is Explained

python object equality: Learn how Python compares objects with == and is, how to implement __eq__ and __hash__, and avoid common equality pitfalls.

pythonobject equality__eq____hash__