Python Question:
Download Questions PDF

Why is not all memory freed when Python exits?

Python Interview Question
Python Interview Question

Answer:

Objects referenced from the global namespaces of Python modules are not always de-allocated when Python exits. This may happen if there are circular references. There are also certain bits of memory that are allocated by the C library that are impossible to free (e.g. a tool like the one Purify will complain about these). Python is, however, aggressive about cleaning up memory on exit and does try to destroy every single object.

If you want to force Python to delete certain things on de-allocation, you can use the at exit module to register one or more exit functions to handle those deletions.

Download Python Interview Questions And Answers PDF

Previous QuestionNext Question
Does Python support strongly for regular expressions? What are the other languages that support strongly for regular expressions?What are the disadvantages of the Python programming language?