3 ms·
> "But if we're strictly speaking about Python objects within pure Python code, then no, memory leaks are not possible - at least not in the traditional sense o
by gravypod 10y ago
> "But if we're strictly speaking about Python objects within pure Python code, then no, memory leaks are not possible - at least not in the traditional sense of the term. The reason is that Python has its own garbage collector (GC), so it should take care of cleaning up unused objects."
I have a hard time beliving this. Java can have memory leaks so why couldn't Python?
- zipfle 10y agoI think that the author is defining memory leaks as permanently out of scope but not deallocated memory. In that sense I don't know of anything in vanilla Python, or Java, that would qualify as a memory leak. In the more intuitive sense of a memory leak being any failure to make objects available to garbage collection, (such as by retaining references to them in an unexpected place) leading to unchecked increases in a program's memory footprint, memory leaks are possible in either language.
- winstonewert 10y agoDifferent definitions of memory leak. In the post's definition, a memory leak is memory you can no longer reach but is still allocated. That's eliminated by Java and Python. Of course, you can still waste memory in Java or Python in a variety of ways. But that's a different definition of memory leak then the post is using.
- bbernard 10y agoCheck out this SO thread: http://stackoverflow.com/questions/2017381/is-it-possible-to-have-an-actual-memory-leak-in-python-because-of-your-code http://stackoverflow.com/questions/2017381/is-it-possible-to.... There are indeed many interpretations of what a memory leak is in Python. In C/C++, you can forget to free memory, thus causing memory leaks. For example, you may call malloc(), but forget to call free(). In Python or Java, you can't do that; you don't need to explicitly "free" objects, as there's a GC. Sure, you could leave rogue Python or Java objects in memory, but in my mind this isn't a "leak" in the same sense as a leak in C/C++. The Python interpreter (which is written in C) or some C extension may themselves cause real leaks, though. I'm the author of the post. Maybe my reasoning was not explained clearly enough.