【问题标题】:igraph for python: memory leak (?) in get_shortest_pathspython的igraph:get_shortest_paths中的内存泄漏(?)
【发布时间】: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


    【解决方案1】:

    我已经对此进行了调查,确实,Graph.get_shortest_paths() 不幸存在无法轻松解决的内存泄漏。我已向解决问题的开发树提交了patch,但不幸的是,如果您想在自己的版本中使用它(或等待下一个小版本),您将不得不从头开始重新编译 Python 接口。

    【讨论】:

    • 非常感谢您修复此漏洞。不幸的是,我现在不知道如何从头开始编译 igraph,所以我将不得不等待下一个版本。是否可以将我的图表传递给子进程并在子进程中运行for v in range(mygrapp.vcount()): 循环?这样每次循环结束时都应该释放内存。
    猜你喜欢
    • 1970-01-01
    • 2012-12-02
    • 2011-12-13
    • 2014-02-26
    • 2010-11-27
    • 1970-01-01
    • 2014-03-01
    • 2012-10-09
    • 2021-07-25
    相关资源
    最近更新 更多