我不知道如何使用 CLion 在 MacOS Big Sur 上使用 CLion 看到内存泄漏,我已经尝试过以下方法:
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -g")
然后我在首选项菜单中写了 -> 地址 sanitizer 部分的 sanitizer : detect_stack_use_after_return=1
基于 CLion 支持页面,他们说 Leak Sanitizer 包含在 Address sanitizer 中。最佳答案
通常你可以在编译期间使用 libasan
(https://www.osc.edu/resources/getting_started/howto/howto_use_address_sanitizer) 但是在 MacOS 上有一些额外的步骤:
https://clang.llvm.org/docs/AddressSanitizer.html(在此页面上搜索“MacOS”以获得概览):
Memory leak detection
For more information on leak detector in AddressSanitizer, see LeakSanitizer. The leak detection is turned on by default on Linux, and can be enabled using ASAN_OPTIONS=detect_leaks=1 on macOS; however, it is not yet supported on other platforms.
来源:https://clang.llvm.org/docs/AddressSanitizer.html
另见 Mac OS: Leaks Sanitizer 和 https://developer.apple.com/documentation/xcode/diagnosing_memory_thread_and_crash_issues_early
关于c - 如何使用 CLion 在 MacOS Big Sur 上查看内存泄漏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66599589/