When i use tensorflow c++ api in my project, GraphDef memory does not release after session->close(). i find same questions in https://github.com/tensorflow/tensorflow/issues/5302
, but use LD_PRELOAD to load tcmalloc can't solve my problem.
ENV Info
CentOS 7
CPU only
tensorflow 1.0 and python 2.7.6
Short code
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);
}
Running it and memory usage would increase。(proportional to graph file size)