My retainCount is increasing?

后端 未结 4 1418
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-04 22:18

am trying here to build rss reader , the problem that when user finish read artical and press back the dealloc don\'t called

and i got retainCount 6 & some times 7

相关标签:
4条回答
  • 2021-02-04 23:06

    I found that the best way to trace retain counts and missing retain-release pairs is using Instruments. Hit Profile (Cmd ⌘+I) and choose Leaks template. Even if leaks will not be discovered automatically, retain changes are logged so you can manually trace additional retains. To do that, find your class name in Object Summary when selected Allocations instrument. If you can't find it, this means that all instances were deallocated. Otherwise click on the arrow that appears when you select class name: Select the class name and click on the arrow to view living instances You will see all living instances of your class: Select the instance and click on the arrow to view its retains/releases

    If you suppose that there are some instances that should be already deallocated, select one and click on the arrow that appeared next to object address. Now you should see any retain or release that was invoked on this object with method name that was performing this action: Double click to see what line of code invoked this retain/release

    RefCt column shows retainCount after action was invoked, and when you double click on any retain/release, instruments will show you line of code where this was performed: Responsible lines are highlighted

    As you see, object is added to an array and never removed from it.

    In my experience this is the fastest and easiest way to find memory leaks that Leaks instrument would not automatically detect. I think another good practice is to look at #Living in Object Summary to ensure that number of living instances are exactly as you'd expect.

    0 讨论(0)
  • 2021-02-04 23:13

    NSThread detachNewThreadSelector:toTarget:withObject: retains its target, which in this case is self. Also, self is the delegate of a few things here, usually you don't want to retain delegates so if you've written those protocols check that you are not doing that.

    0 讨论(0)
  • 2021-02-04 23:16

    Strange as it may seem, retainCount is not useful at all for counting your retains. Things get retained for other reasons than you calling [myObject retain] or [[MyClass alloc] init] etc.

    It's better to ignore retainCount and learn the memory management rules. retainCount will make you more confused. If you're developing only for iOS 5, it's better to forget about memory management and use ARC.

    0 讨论(0)
  • 2021-02-04 23:17

    You have no reason to care what the retain count is. Just make sure you balance your retains and releases.

    0 讨论(0)
提交回复
热议问题