我有一个全局变量cv::Mat imageInputRGBA
我希望在清理函数的程序结束时释放它。但我从Valgrind
收到如下所示的内存泄漏消息。任何人都可以给我任何建议如何在没有内存泄漏的情况下正确释放Mat
内存?:
==4499== Memcheck, a memory error detector
==4499== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==4499== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
==4499== Command: ./nwcc7 im2.png im6.png
==4499==
==4499==
==4499== HEAP SUMMARY:
==4499== in use at exit: 6,086 bytes in 3 blocks
==4499== total heap usage: 412 allocs, 409 frees, 25,693,438 bytes allocated
==4499==
==4499== 30 bytes in 1 blocks are still reachable in loss record 1 of 3
==4499== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4499== by 0x5D64679: strdup (strdup.c:42)
==4499== by 0x698D59E: ??? (in /usr/lib/nvidia-331-updates/libGL.so.331.38)
==4499== by 0x6578652F3938: ???
==4499==
==4499== 32 bytes in 1 blocks are still reachable in loss record 2 of 3
==4499== at 0x4C2CC70: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4499== by 0x60A268F: _dlerror_run (dlerror.c:141)
==4499== by 0x60A2197: dlsym (dlsym.c:70)
==4499== by 0x698B8BD: ??? (in /usr/lib/nvidia-331-updates/libGL.so.331.38)
==4499== by 0x6BCD5BF: ??? (in /usr/lib/nvidia-331-updates/libGL.so.331.38)
==4499== by 0x6C00A5F: ???
==4499== by 0x69B12CA: ??? (in /usr/lib/nvidia-331-updates/libGL.so.331.38)
==4499==
==4499== 6,024 bytes in 1 blocks are definitely lost in loss record 3 of 3
==4499== at 0x4C2CC70: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4499== by 0x69A427E: ??? (in /usr/lib/nvidia-331-updates/libGL.so.331.38)
==4499==
==4499== LEAK SUMMARY:
==4499== definitely lost: 6,024 bytes in 1 blocks
==4499== indirectly lost: 0 bytes in 0 blocks
==4499== possibly lost: 0 bytes in 0 blocks
==4499== still reachable: 62 bytes in 2 blocks
==4499== suppressed: 0 bytes in 0 blocks
==4499==
==4499== For counts of detected and suppressed errors, rerun with: -v
==4499== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
// -------------------------------------- 代码是这样的:
cv::Mat imageInputRGBA;
void CPU_cleanUp(){
imageInputRGBA.release();
}
int main(int argc, char **argv) {
CPU_Part(argc,argv);// I didn't use imageInputRGBA in CPU_Part
CPU_cleanUp();
return 0;
}