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.