如何解决 OS X 上 libobjc.A.dylib 造成的的内存泄露问题?

2016-03-09 15:38:19 +08:00
 oIMOo

使用 valgrind 对 C 检查内存时, OS X 上永远有内存泄露问题。
同样的代码放在 Linux 上完全没有问题。

如:
int main(){
return 123;
}

valgrind 返回:

HEAP SUMMARY:
==4020== in use at exit: 22,146 bytes in 187 blocks
==4020== total heap usage: 271 allocs, 84 frees, 28,386 bytes allocated
==4020==
==4020== 2,064 bytes in 1 blocks are possibly lost in loss record 57 of 62
==4020== at 0x10000817C: malloc_zone_malloc (in /usr/local/Cellar/valgrind/3.11.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==4020== by 0x1004F3EFD: _objc_copyClassNamesForImage (in /usr/lib/libobjc.A.dylib)
==4020== by 0x1004E7182: protocols() (in /usr/lib/libobjc.A.dylib)
==4020== by 0x1004E7093: readClass(objc_class, bool, bool) (in /usr/lib/libobjc.A.dylib)
==4020== by 0x1004E4C13: gc_init (in /usr/lib/libobjc.A.dylib)
==4020== by 0x1004EC24E: objc_initializeClassPair_internal(objc_class
, char const, objc_class, objc_class) (in /usr/lib/libobjc.A.dylib)
==4020== by 0x1004F9132: layout_string_create (in /usr/lib/libobjc.A.dylib)
==4020== by 0x1004E783C: realizeClass(objc_class
) (in /usr/lib/libobjc.A.dylib)
==4020== by 0x1004E7300: copySwiftV1MangledName(char const, bool) (in /usr/lib/libobjc.A.dylib)
==4020== by 0x1004E72E9: copySwiftV1MangledName(char const
, bool) (in /usr/lib/libobjc.A.dylib)
==4020== by 0x1004E72E9: copySwiftV1MangledName(char const, bool) (in /usr/lib/libobjc.A.dylib)
==4020== by 0x1004E72E9: copySwiftV1MangledName(char const
, bool) (in /usr/lib/libobjc.A.dylib)
==4020==
==4020== LEAK SUMMARY:
==4020== definitely lost: 0 bytes in 0 blocks
==4020== indirectly lost: 0 bytes in 0 blocks
==4020== possibly lost: 2,064 bytes in 1 blocks
==4020== still reachable: 0 bytes in 0 blocks
==4020== suppressed: 20,082 bytes in 186 blocks
==4020==
==4020== For counts of detected and suppressed errors, rerun with: -v
==4020== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 17 from 17)

按照网上找的教程,将如下文件加入到 valgrind 的执行过程中。

{
<insert_a_suppression_name_here>
Memcheck:Leak
match-leak-kinds: indirect
fun:malloc
fun:Balloc_D2A
fun:
rvalloc_D2A
fun:
dtoa
fun:
vfprintf
fun:
_v2printf
fun:vfprintf_l
fun:printf
fun:main
}
摘自: http://stackoverflow.com/questions/34573039/possible-memory-leak-valgrind-in-osx-el-capitan/35592274

只是屏蔽了内存泄露的具体信息,有没有什么方法,能从根本上解决?
目的: allocs = frees

4037 次点击
所在节点    问与答
1 条回复
oIMOo
2016-03-15 21:35:35 +08:00
自己顶一下

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/262218

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX