0

In a python function, it creates a dictionary contains 2 objects a and b; object a is referenced by a global variable. object b is not referenced after function exits.

Will the dictionary (and object b) be released by python after function exits? Will it has memory leak?

Thanks!

whataday
  • 47
  • 3
  • If this causes a memory leak, then Python is broken. – ggorlen May 24 '20 at 05:02
  • It will free both b and the dict. According to your description the only references to these objects are the in function. When the function's local variables go out of scope, python decrements the references they have. When the references reach zero, the objects are deleted. – tdelaney May 24 '20 at 05:05
  • 1
    Does this answer your question? [Is it possible to have an actual memory leak in Python because of your code?](https://stackoverflow.com/questions/2017381/is-it-possible-to-have-an-actual-memory-leak-in-python-because-of-your-code) – ggorlen May 24 '20 at 05:06

0 Answers0