gpt4 book ai didi

c - OpenCV cvReleaseMat 内存分配错误

转载 作者:行者123 更新时间:2023-11-30 17:50:19 25 4
gpt4 key购买 nike

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

当我尝试使用cvReleaseMat(&trainData)释放此矩阵

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

我的疑问是...cvReleaseMat也会释放CPU中的内存吗?或者它只是使该矩阵在未来变得不可见?

最佳答案

是的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

关于c - OpenCV cvReleaseMat 内存分配错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17340542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com