0

有没有大神能解释一下为什么 Python 循环中无法释放内存

 2 years ago
source link: https://www.v2ex.com/t/824267
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  Python

有没有大神能解释一下为什么 Python 循环中无法释放内存

  liuxingdeyu · 3 小时 20 分钟前 · 380 次点击
工作中遇到一个问题,启动多个 worker 去跑任务,任务是把用 bfmatch 去匹配特征点,由于图量比较大,导致一直爆内存,现在用了一个监控内存后重启进程的临时办法,然后自己写了个例子:
while True:
x = []
for i in range(10000000000):
x.append(i)
这样内存也会很快堆起来
然后做了这样的改动:
while True:
x = []
for i in range(10000000000):
x.append(i)
del x
gc.collect()
这样内存依旧会很快堆起来
希望有大佬能解释一下原因,顺便谁能推荐个 python 查看堆栈的工具,万分感谢

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK