garbage-collection

How does Python's Garbage Collector Detect Circular References?

How does Python's Garbage Collector Detect Circular References? Question: I’m trying to understand how Python’s garbage collector detects circular references. When I look at the documentation, all I see is a statement that circular references are detected, except when the objects involved have a __del__ method. If this happens, my understanding (possibly faulty) is that …

Total answers: 3

What is a reference cycle in python?

What is a reference cycle in python? Question: I have looked in the official documentation for python, but i cannot seem to find what a reference cycle is. Could anyone please clarify what it is for me, as i am trying to understand the GC module. Thank you in advance for your replies. Asked By: …

Total answers: 4

How to force deletion of a python object?

How to force deletion of a python object? Question: I am curious about the details of __del__ in python, when and why it should be used and what it shouldn’t be used for. I’ve learned the hard way that it is not really like what one would naively expected from a destructor, in that it …

Total answers: 4

Python garbage collector documentation

Python garbage collector documentation Question: I’m looking for documents that describes in details how python garbage collection works. I’m interested what is done in which step. What objects are in these 3 collections? What kinds of objects are deleted in each step? What algorithm is used for reference cycles finding? Background: I’m implementing some searches …

Total answers: 1

Are all Python objects tracked by the garbage collector?

Are all Python objects tracked by the garbage collector? Question: I’m trying to debug a memory leak (see question Memory leak in Python Twisted: where is it?). When the garbage collector is running, does it have access to all Python objects created by the Python interpreter? If we suppose Python C libraries are not leaking, …

Total answers: 3

Python garbage collection can be that slow?

Python garbage collection can be that slow? Question: I have a problem with my python application, and I think it’s related to the python garbage collection, even if I’m not sure… The problem is that my application takes a lot of time to exit and to switch to one function to the next one. In …

Total answers: 3

for line in open(filename)

for line in open(filename) Question: I frequently see python code similar to for line in open(filename): do_something(line) When does filename get closed with this code? Would it be better to write with open(filename) as f: for line in f.readlines(): do_something(line) Asked By: foosion || Source Answers: The with part is better because it close the …

Total answers: 4

Python garbage collection

Python garbage collection Question: I have created some python code which creates an object in a loop, and in every iteration overwrites this object with a new one of the same type. This is done 10.000 times, and Python takes up 7mb of memory every second until my 3gb RAM is used. Does anyone know …

Total answers: 7

Why Java and Python garbage collection methods are different?

Why Java and Python garbage collection methods are different? Question: Python uses the reference count method to handle object life time. So an object that has no more use will be immediately destroyed. But, in Java, the GC(garbage collector) destroys objects which are no longer used at a specific time. Why does Java choose this …

Total answers: 9