c++ - OpenCV Error: insufficient memory, in function call -
i have function looks this:
void foo(){ mat mat(50000, 200, cv_32fc1); /* manipulation using mat */ }
then after several loops (in each loop, call foo()
once), gives error:
opencv error: insufficient memory when allocating (about 1g) memory.
in understanding, mat
local , once foo()
returns, automatically de-allocated, wondering why leaks.
and leaks on data, not of them.
here actual code:
bool vidbow::readfeatpoints(int sidx, int eidx, cv::mat &keys, cv::mat &descs, cv::mat &codes, int &barrier) { // initialize buffers keys , descriptors int num = 50000; /// large number int ndims = 0; /// feature dimensions if (featname == "stip") ndims = 162; mat descsbuff(num, ndims, cv_32fc1); mat keysbuff(num, 3, cv_32fc1); mat codesbuff(num, 3000, cv_64fc1); // move overlapping codes previous window buffer int idxpre = -1; int numpre = keys.rows; int nummov = 0; /// number of overlapping points move (int = 0; < numpre; ++i) { if (keys.at<float>(i, 0) >= sidx) { idxpre = i; break; } } if (idxpre > 0) { nummov = numpre - idxpre; keys.rowrange(idxpre, numpre).copyto(keysbuff.rowrange(0, nummov)); codes.rowrange(idxpre, numpre).copyto(codesbuff.rowrange(0, nummov)); } // starting row in code matrix new codes updated features add in barrier = nummov; // read keys , descriptors feature file int count = 0; /// number of new points read in buffers if (featname == "stip") count = readstipfeatpoints(nummov, eidx, keysbuff, descsbuff); // update keys, descriptors , codes matrix descsbuff.rowrange(0, count).copyto(descs); keysbuff.rowrange(0, nummov+count).copyto(keys); codesbuff.rowrange(0, nummov+count).copyto(codes); // see if reaching end of feature file bool flag = false; if (feof(fpfeat)) flag = true; return flag; }
you don't post code calls function, can't tell whether true memory leak. mat
objects allocate inside readfeatpoints()
deallocated correctly, there no memory leaks can see.
you declare mat codesbuff(num, 3000, cv_64fc1);
. num = 5000
, means you're trying allocate 1.2 gigabytes of memory in 1 big block. copy of data codes
line:
codesbuff.rowrange(0, nummov+count).copyto(codes);
if value of nummove + count
changes between iterations, cause reallocation of data buffer in codes
. if value large enough, may eating significant amount of memory persists across iterations of loop. both of these things may leading heap fragmentation. if @ point there doesn't exist 1.2 gb chunk of memory waiting around, insufficient memory error occurs, have experienced.
Comments
Post a Comment