Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in InternalThread::StartInternalThread() #1316

Closed
ryotat opened this issue Oct 17, 2014 · 9 comments
Closed

Memory leak in InternalThread::StartInternalThread() #1316

ryotat opened this issue Oct 17, 2014 · 9 comments

Comments

@ryotat
Copy link

ryotat commented Oct 17, 2014

I think the following line

thread_ = new caffe::Thread
        (&InternalThread::InternalThreadEntry, this);

is causing a memory leak because this function is called every time BasePrefetchingDataLayer::Forward_cpu() is called and the allocated memory is not freed.

@jeffdonahue
Copy link
Contributor

Good point -- thread_ should probably be changed from a caffe::Thread* to a shared_ptr<caffe::Thread>.

@ryotat
Copy link
Author

ryotat commented Oct 17, 2014

Thanks for your reply. How about this line

  this->thread_ = new boost::thread(func, a1);

Isn't this also leaking? caffe::Thread does not seem to have a destructor. By the way, why are the member functions of caffe::Thread class in include/caffe/util/thread.hpp?

@jeffdonahue
Copy link
Contributor

Yup, looks like a memory leak as well.

By the way, why are the member functions of caffe::Thread class in include/caffe/util/thread.hpp?

Not sure...this is my first time looking at all this code; seems it could use a good round of cleanups... (please feel free to send a PR).

@shelhamer
Copy link
Member

@ryotat thanks for the close look and catching these issues! A fix is certainly in order, so a PR would be welcome!

@shelhamer shelhamer added the bug label Oct 17, 2014
@ryotat
Copy link
Author

ryotat commented Oct 18, 2014

hmmm, I think I fixed this but I still have a problem that the amount of memory consumed by caffe increases linearly with the number of iterations. Is this a normal behavior? I was looking at the output of valgrind and found the above leak.

My issue might be related to this, but I am having the issue with both leveldb and LMDB.

@shelhamer
Copy link
Member

@ryotat please PR your fix -- your cleanup is likely right but there is a recent issue with the data pipeline introduced in #1238 that we are fixing now.

@cvondrick
Copy link

After applying the fix suggested by ryotat, I still notice a leak on the latest master branch, supporting ryotat's observation that this may be a more complex leak. caffe memory usage increases on each iteration linearly, reaching tens of gigabytes and beyond.

The problem appears to be related to this line: https://github.com/BVLC/caffe/blob/master/src/caffe/layers/data_layer.cpp#L167. If I comment it out, memory remains mostly constant. However, I find it very difficult to believe that this is a bug is due to Google's protobuf library!

@ryotat
Copy link
Author

ryotat commented Nov 8, 2014

Thanks for confirming my observation. It would be great if somebody with a better understanding of how protobuf / LMDB works could look into this.

@shelhamer
Copy link
Member

Thread leak fixed by #1335.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants