Loading topic
id() values and reference counts can differ in other im3 min readis compares identity while == compares value. You should also be comfortable with lists, dictionaries, and function calls.2 min readdel does, and why __del__ is a poor place for cleanup.2 min readgc module's basic existence.3 min readsys.getsizeof reports, why that number is often misleading, and how to estimate the full size of a structure.2 min readsys.getsizeof reports an object's size. Here you will see where the bytes for those objects come from.3 min readis compares identity while == compares value. Everything here describes CPython, and the exact behavior can change between versions.2 min readsys.getsizeof and the idea of a shallow size. By the end you will know what __slots__ changes inside an instance, how to measure the saving, and which restrictions come with it.2 min readsys.getsizeof. A generator is an object that produces values one at a time, on demand, instead of building them all up front.2 min readsys.getsizeof reports shallow sizes, and how reference counting frees objects. It shows how to find which lines of your program hold memory.3 min readtracemalloc. A Python leak is almost never memory the interpreter lost. It is an object you still reference, so the collector is right not to free it.2 min readgc module lets you observe the cyclic collector and change when it runs. Most programs never need to change it. Learn to inspect it first, and tune it2 min read