【发布时间】:2014-11-07 14:37:32
【问题描述】:
我有大量不同的图表(每个 8000 多个节点)。在 python 2.7 的 igraph(0.7.0 版)中,我试图对从这些图计算的最短路径执行一些计算。在循环中,将每个图导入 igraph,然后计算最短路径。但是,我注意到 python 使用的内存在每个循环期间都会增加(即使每个循环中都使用了新的图表)。一段时间后,由于内存被填满,我的程序崩溃了。这是否表明 igraph 中存在内存泄漏?我怎样才能最好地解决这个问题?
这种内存泄漏 (?) 可以用下面的 python 代码演示:
import igraph as ig
import psutil, os
# Perform the operation below 100 times.
for run in range(100):
mygraph = ig.Graph.Full(300)
# To speed up calculations only the nodes that can be reached in 10 steps are considered for the shortest paths
ig10neigh = mygraph.neighborhood(order = 10, mode = 'out')
for v in range(mygraph.vcount()):
paths = mygraph.get_shortest_paths(v, ig10neigh[v], mode = 'out', output = 'epath')
#Here some calculations with the paths
print psutil.Process(os.getpid()).get_memory_info()[0] / float(2 ** 20) # Print the memory use
当我运行上述代码时,我的内存使用量从 22 MB 缓慢增加到 100 MB。
感谢您的帮助!
【问题讨论】:
标签: python python-2.7 memory-leaks igraph