内存分配错误OpenCV cvReleaseMat

时间:2013-06-27 10:19:09

标签: c opencv

CvMat* traindata=cvCreateMat(1000,36,CV_32FC1);

当我尝试使用cvReleaseMat(&trainData)

发布此矩阵时

我发现任务管理器中的内存没有减少......相反,此发布命令对任务管理器中此应用程序的内存没有任何影响。

我怀疑的是...... cvReleaseMat是否也释放了CPU中的内存?或者它是否会在未来使该矩阵变得无形?

1 个答案:

答案 0 :(得分:0)

cvReleaseMat确实释放了内存。任务管理器实际上并不是查看CvMat *分配内存的工具。虽然如果你想使矩阵更大,你可能会注意到它。该矩阵占用1000 * 36 * 4 = 144000字节。

您可以在valgrind分析的以下代码的输出中看到它:

CvMat* traindata = cvCreateMat(1000, 36, CV_32FC1);
//cvReleaseMat(&traindata);

相关的valgrind输出是:

==4967== HEAP SUMMARY:
==4967==     in use at exit: 144,108 bytes in 2 blocks
==4967==   total heap usage: 10 allocs, 8 frees, 144,772 bytes allocated
==4967== 
==4967== LEAK SUMMARY:
==4967==    definitely lost: 64 bytes in 1 blocks
==4967==    indirectly lost: 144,044 bytes in 1 blocks
==4967==      possibly lost: 0 bytes in 0 blocks
==4967==    still reachable: 0 bytes in 0 blocks
==4967==         suppressed: 0 bytes in 0 blocks

但如果您确实发布了CvMat

CvMat* traindata = cvCreateMat(1000, 36, CV_32FC1);
cvReleaseMat(&traindata);

你现在得到这个输出通知valgrind的输出:

==4957== HEAP SUMMARY:
==4957==     in use at exit: 0 bytes in 0 blocks
==4957==   total heap usage: 10 allocs, 10 frees, 144,772 bytes allocated
==4957== 
==4957== All heap blocks were freed -- no leaks are possible