Is it possible to have an actual memory leak in Python because of your code?

后端 未结 6 975
时光取名叫无心
时光取名叫无心 2020-12-12 13:58

I don\'t have a code example, but I\'m curious whether it\'s possible to write Python code that results in essentially a memory leak.

6条回答
  •  眼角桃花
    2020-12-12 14:10

    The classic definition of a memory leak is memory that was used once, and now is not, but has not been reclaimed. That nearly impossible with pure Python code. But as Antoine points out, you can easily have the effect of consuming all your memory inadvertently by allowing data structures to grow without bound, even if you don't need to keep all of the data around.

    With C extensions, of course, you are back in unmanaged territory, and anything is possible.

提交回复
热议问题