mini-caffe icon indicating copy to clipboard operation
mini-caffe copied to clipboard

Memory Leak when using Threads

Open 1nFl4me2 opened this issue 7 years ago • 2 comments
trafficstars

Hi,

When i create a new caffe::Net object in a Thread the memory is not freed.

Below example without Thread works fine and frees memory:

int main()
{
     for(int i=0;i<10;i++)
    {
        caffe::Net* cnn = new caffe::Net(("deploy.prototxt"));
        delete cnn;
    }
    std::cin.ignore();
    return 0;
}

The below example using Threads doesn't free memory

void threadWork()
{
        caffe::Net* cnn = new caffe::Net(("deploy.prototxt"));
        delete cnn;
}

int main()
{
     for(int i=0;i<10;i++)
    {
        std::thread t1(threadWork);
        t1.join();
    }
    std::cin.ignore();
    return 0;
}

Do you know what is causing this?

1nFl4me2 avatar Jun 26 '18 02:06 1nFl4me2

memory pool manager is used for every thread, and these instances only freed when the program exit. check the code here and here

luoyetx avatar Jun 29 '18 00:06 luoyetx

为什么在我的程序里面delete cnn就出错?

Lin427 avatar Oct 10 '19 07:10 Lin427