开发者

navigationBar tintColor memory leak

i will change navigationBar tintColor in viewWillAppear: self.navigationController.navigationBar.tintColor = tintColor;

in viewWillDisappear: NSLog(@"be开发者_开发问答fore retain count:%d", [tintColor retainCount]); self.navigationController.navigationBar.tintColor = nil; NSLog(@"after retain count:%d", [tintColor retainCount]);

tintColor = [[UIColor colorWithRed:23.0/255.0 green:169.0/255.0 blue:226.0/255.0 alpha:1.0] retain];

why nslog "before retain count" and "after retain count" is equal?


It could be a kind of over-retention.

You assign a tintColor to the tintColor property of a UINavigationBar object. This calls the setter of the UINavigationBar for the tintColor property which sends a retain-message to the given tintColor to be set.

I interpret the last line of code

tintColor = [[UIColor colorWithRed:23.0/255.0 green:169.0/255.0 blue:226.0/255.0 alpha:1.0] retain];

as the one where you create your custom tintColor. The last retain is the problem. You can do it, but you have to release it somewhere after to get the reference counted memory cleanup to work.

Look at the class reference at Apple UINavigationBar Class Reference for the property declarations.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜