Heater wrote:How does one actually make a memory leak in Python?
I thought part of the point of Python is that you cannot.
Whilst Python uses reference counting for most of it's memory management there are times (cyclic references) where it doesn't work. For these cases there is a garbage collector which tries to free up objects but it used to be limited in cases where objects have their own __del__()
functions where Python can't determine which object to free first (they fixed it in 3.4 for all but foreign objects). In these cases it does the safest thing which is to stick the objects in a list of objects which can't be freed (gc.garbage
) and take the memory loss (leaving it up to you to fix it yourself and remove the entries from the list).
From Python 3.4 they changed things and I think the only cases where objects don't get freed now is when you have foreign objects (e.g. stuff written in C) that still use the old tp_del
rather than the new tp_finalize