Finding all references to an object instance in Obj-C

后端 未结 3 2086
盖世英雄少女心
盖世英雄少女心 2021-02-13 18:55

I\'m trying to track down some bugs, and one of them is related to a memory leak. It\'s an object that I can tell that something still has a reference to, since Instruments stil

3条回答
  •  鱼传尺愫
    2021-02-13 19:50

    Cautionary Tail: :) In the process of searching for a memory leak, I set a breakpoint (really a logpoint) in Xcode that would log the value of self when it was triggered troublesome logpoint image. Meanwhile I found the leak and patched it, but the memory usage wasn't leveling out, and my de-init was never getting called. The logpoint I set earlier was actually causing the retain count of my object to increase, and in turn that prevented de-init from ever getting called. I happened to discover this after several hours of wild goose chases which culminated in me stepping through my object's methods line by line, issuing p CFGetRetainCount(self) from debug console. When I stepped over the line with the logpoint, the retain count went up. At first I assumed it was some strange side effect of my code. I moved that logpoint so that I could set a normal breakpoint on that line, and my problem moved with it. I disabled the logpoint and the leak was gone. Hopefully this can help someone else.

提交回复
热议问题