How Does Python Memory Management Work?

后端 未结 5 1308
耶瑟儿~
耶瑟儿~ 2020-12-23 22:22

Okay, I got this concept of a class that would allow other classes to import classes on as basis versus if you use it you must import it. How would I go about implementing i

5条回答
  •  一生所求
    2020-12-23 22:47

    My 5 cents:

    1. most importantly, python frees memory for referenced objects only (not for classes because they are just containers or custom data types). Again, in python everything is an object, so int, float, string, [], {} and () all are objects. That mean if your program don't reference them anymore they are victims for garbage collection.

    2. Though python uses'Reference count' and 'GC' to free memory (for the objects that are not in used), this free memory is not returned back to the operating system (in windows its different case though). This mean free memory chunk just return back to python interpreter not to the operating system. So utlimately your python process is going to hold the same memory. However, python will use this memory to allocate to some other objects.

    Very good explanation for this given at: http://deeplearning.net/software/theano/tutorial/python-memory-management.html

提交回复
热议问题