tensorflow c ++ api内存泄漏

时间:2017-07-03 07:11:05

标签: c++ memory-leaks tensorflow

当我在我的项目中使用tensorflow c ++ api时,GraphDef内存在session-> close()之后不会释放。我在https://github.com/tensorflow/tensorflow/issues/5302中找到了相同的问题 ,但使用LD_PRELOAD加载tcmalloc无法解决我的问题 ENV信息
CentOS 7
CPU只有 tensorflow 1.0和python 2.7.6
短代码

for (int i = 1; i < 10; i++)
{
    GraphDef graph_def;
    Status status = ReadBinaryProto(Env::Default(), "models/graph.pb", &graph_def);
    if (!status.ok()) {
        std::cout << status.ToString() << "\n";
        return 1;
    }
    // Initialize a tensorflow session
    Session* session;
    status = NewSession(SessionOptions(), &session);
    if (!status.ok()) {
        std::cout << status.ToString() << "\n";
        return 1;
    }
    cout << "____Load graph success____!" << "\n";
    // Add the graph to the session
    status = session->Create(graph_def);
    if (!status.ok()) {
        std::cout << status.ToString() << "\n";
        return 1;
    }
    sleep(5);
    session->Close();
    cout << "----Close graph success----!" << "\n";
    sleep(5);
}

运行它和内存使用会增加。(与图形文件大小成比例)

0 个答案:

没有答案