caffe icon indicating copy to clipboard operation
caffe copied to clipboard

set_data_array takes memory and never frees it

Open kevin-li opened this issue 10 years ago • 5 comments

I am using MemoryData layer to run in test phase. Multiple calls to set_input_arrays in a for-loop seems to take more and more memory unless I reconstruct the net by caffe.Net after some iterations. Why is this happening?

kevin-li avatar May 26 '16 19:05 kevin-li

One clue is that less memory is taken with smaller batch size, which is kinda expected...

kevin-li avatar May 27 '16 16:05 kevin-li

I have the same issue, have you managed to solve it?

ZhengRui avatar Mar 17 '17 16:03 ZhengRui

No... I just reload the network after every 100 calls to that function

kevin-w-li avatar Mar 17 '17 16:03 kevin-w-li

I found the solution, the reason memory data layer does not release memory is because in Net_SetInputArrays function of _caffe.cpp file, the creation of data_arr and labels_arr object will increase the reference count of corresponding python objects, but in the end of this function it does not decrease it back, which causes memory leak when you update the python objects. The solution is add

Py_DECREF(data_arr);
Py_DECREF(labels_arr);

at the end of this function. Reference:

https://jianfengwang.wordpress.com/tag/python-numpy-cc/

ZhengRui avatar Mar 17 '17 20:03 ZhengRui

Closing according to #5528.

shelhamer avatar Apr 13 '17 20:04 shelhamer