은 다음과 같습니다OpenCV의 오류 : 메모리 부족, 함수 호출에 나는 기능이
:void foo(){
Mat mat(50000, 200, CV_32FC1);
/* some manipulation using mat */
}
여러 루프 (각 루프에서, 한번 foo()
전화) 그런 후, 에러를 제공합니다
OpenCV Error: insufficient memory when allocating (about 1G) memory.
Mat
은 로컬이며 foo()
이 반환되면 자동으로 할당이 해제되므로 왜 누설되는지 궁금합니다.
일부 데이터는 누출되지만 전부는 아닙니다.
bool VidBOW::readFeatPoints(int sidx, int eidx, cv::Mat &keys, cv::Mat &descs, cv::Mat &codes, int &barrier) {
// initialize buffers for keys and descriptors
int num = 50000; /// a 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 from a previous window to buffer
int idxPre = -1;
int numPre = keys.rows;
int numMov = 0; /// number of overlapping points to move
for (int i = 0; i < 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));
}
// the starting row in code matrix where new codes from the updated features to add in
barrier = numMov;
// read keys and descriptors from feature file
int count = 0; /// number of new points that are read in buffers
if (featName == "STIP")
count = readSTIPFeatPoints(numMov, eidx, keysBuff, descsBuff);
// update keys, descriptors and 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 the end of a feature file
bool flag = false;
if (feof(fpfeat))
flag = true;
return flag;
}
게시 한 코드로는 [문제 재현] (http://SSCCE.org) 할 수 없습니다. 간단하지만 메모리 누수를 나타내는 샘플을 게시하십시오. – Aurelius