Python garbage collection

2019-01-22 11:23发布

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 of a way to remove the objects from memory?

7条回答
Bombasti
2楼-- · 2019-01-22 12:08

If you're creating circular references, your objects won't be deallocated immediately, but have to wait for a GC cycle to run.

You could use the weakref module to address this problem, or explicitly del your objects after use.

查看更多
登录 后发表回答