NSString retain count -1

前端 未结 3 571
走了就别回头了
走了就别回头了 2021-01-21 09:09

I want to print retain count of NSString in AppDelegate class in didFinishLaunchingWithOptions method

NSString *str = [[N         


        
3条回答
  •  长发绾君心
    2021-01-21 09:41

    Apple docs say:

    Special Considerations

    This method is of no value in debugging memory management issues. Because any number of framework objects may have retained an object in order to hold references to it, while at the same time autorelease pools may be holding any number of deferred releases on an object, it is very unlikely that you can get useful information from this method.

    So you shouldn't count on its correctness.

    Also, -1 is actually largest unsigned integer, not negative value. Retain count returns NSUInteger, so you should use %u instead of %d.

提交回复
热议问题