我正在使用 Clion,我想找到一种方法来查找 Mac M1 上的内存泄漏。尚不支持 Valgrind。
让我们看一下这个带有内存泄漏的简单代码:
// Program with memory leak
#include <cstdlib>
using namespace std;
// function with memory leak
void func_to_show_mem_leak()
{
int* ptr = new int(5);
// body
// return without deallocating ptr
return;
}
// driver code
int main()
{
// Call the function
// to get the memory leak
func_to_show_mem_leak();
system("leaks SimpleMemoryLeak");
return 0;
}
我试过使用泄漏:
leaks *NameOfProccess*
我得到这个输出:
Process 70526 is not debuggable. Due to security restrictions, leaks can only show or save contents of readonly memory of restricted processes.
Process: SimpleMemoryLeak [70526]
Path: /Users/USER/Documents/*/SimpleMemoryLeak
Load Address: 0x100ec8000
Identifier: SimpleMemoryLeak
Version: ???
Code Type: ARM64
Parent Process: clion [39550]
Date/Time: 2021-12-05 23:32:52.942 +0100
Launch Time: 2021-12-05 23:32:52.307 +0100
OS Version: macOS 12.0.1 (21A559)
Report Version: 7
Analysis Tool: /usr/bin/leaks
Physical footprint: 945K
Physical footprint (peak): 945K
----
leaks Report Version: 4.0
Process 70526: 208 nodes malloced for 12 KB
Process 70526: 1 leak for 16 total leaked bytes.
1 (16 bytes) ROOT LEAK: 0x6000003ac030 [16]
有什么方法可以获取 malloc 所在的确切代码行吗?谢谢!