V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
oIMOo
V2EX  ›  问与答

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

  •  
  •   oIMOo · 2016-03-09 15:38:19 +08:00 · 4034 次点击
    这是一个创建于 3182 天前的主题,其中的信息可能已经有所发展或是发生改变。

    使用 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

    1 条回复    2016-03-15 21:35:35 +08:00
    oIMOo
        1
    oIMOo  
    OP
       2016-03-15 21:35:35 +08:00
    自己顶一下
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2872 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 11:58 · PVG 19:58 · LAX 03:58 · JFK 06:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.