I was having memory leaks using a code structure like this (OpenCV with C++):
int i;
while(true){
Mat x = imread("C:/pics"+i+".jpg");
//do something with x
}
After 100 or so iterations it always crashed, then i changed the code to this:
int i;
while(true){
Mat x = imread("C:/pics"+i+".jpg");
//do something with x
x.refcount = 0;
x.release();
}
It stopped crashing and did the full iteration. But when setting the refcount manually to 0 you must be really sure that you dont need the object anymore. Thats probably the reason for someone to down-vote my answer, but I solved my problem using this approach. So why shouldn't i share it?