我是 valgrind 的新手,首先要注意的是,OS X El Capitan上的标准C-Library似乎泄漏了内存(可能丢失了) 。在稍微阅读之后,情况并非如此,并且可以使用抑制文件从 valgrind泄漏摘要中排除system-lib。
我生成了一个这样的抑制文件(通过运行一个简单的程序)并将错误添加到抑制文件中。它看起来像这样:
osx_el_capitan_c_lib.supp
{
<osx_el_capitan_c_lib>
Memcheck:Leak
match-leak-kinds: possible
fun:malloc_zone_malloc
fun:_objc_copyClassNamesForImage
fun:_ZL9protocolsv
fun:_Z9readClassP10objc_classbb
fun:gc_init
fun:_ZL33objc_initializeClassPair_internalP10objc_classPKcS0_S0_
fun:layout_string_create
fun:_ZL12realizeClassP10objc_class
fun:_ZL22copySwiftV1MangledNamePKcb
fun:_ZL22copySwiftV1MangledNamePKcb
fun:_ZL22copySwiftV1MangledNamePKcb
fun:_ZL22copySwiftV1MangledNamePKcb
}
现在我有几个问题:
==37004== Memcheck, a memory error detector ==37004== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al. ==37004== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info ==37004== Command: ./val.o ==37004== ==37004== ==37004== HEAP SUMMARY: ==37004== in use at exit: 22,100 bytes in 187 blocks ==37004== total heap usage: 271 allocs, 84 frees, 28,340 bytes allocated ==37004== ==37004== LEAK SUMMARY: ==37004== definitely lost: 0 bytes in 0 blocks ==37004== indirectly lost: 0 bytes in 0 blocks ==37004== possibly lost: 0 bytes in 0 blocks ==37004== still reachable: 0 bytes in 0 blocks ==37004== suppressed: 22,100 bytes in 187 blocks ==37004== ==37004== For counts of detected and suppressed errors, rerun with: -v ==37004== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 18 from 18)正如您所看到的,抑制文件现在非常有用(没有字节显示为丢失等)。但是堆摘要不会受到它看起来的抑制文件的影响(显示
allocs
/ mallocs
- 它们发生在我的代码之外)并且泄漏摘要显示被抑制这是自己的领域。有没有办法可以禁用此字段(标志或其他内容)并抑制堆摘要中的(allocs
/ mallocs
在我的代码之外)?