UILabel的文本设置分析奇怪的内存泄漏
当我产品>时分析 clang 分析器给我一个我不明白的内存泄漏。它说我在第二行中泄漏了以下代码第一行中初始化的内容,
[[testView newScore] setText: [NSString stringWithFormat: @"+%d", addScore]];
[[testView newScore] setTextColor: [UIColor greenColor]];
因为 Instruments 现在无法工作(我正在使用带有 SDK 4.3 的 Xcode 4.1),我无法进一步调查此泄漏。
您知道为什么这可能是内存泄漏吗?属性 newScore
定义如下:
@property (nonatomic, retain) UILabel *newScore;
testView
是 UIView
的子类。
编辑:分析器输出的屏幕截图:
感谢您的阅读!
When I Product > Analyze
the clang analyzer gives me a memory leak I do not understand. It says that I am leaking in the second line something what was initialized in the first line of the following code
[[testView newScore] setText: [NSString stringWithFormat: @"+%d", addScore]];
[[testView newScore] setTextColor: [UIColor greenColor]];
As Instruments isn't working right now (I am using Xcode 4.1 with SDK 4.3) I can't investigate this leak any further.
Do you see why this could be a memory leak. The property newScore
is defined like this:
@property (nonatomic, retain) UILabel *newScore;
and testView
is a subclass of UIView
.
Edit: Screenshot of the analyzer output:
Thank you for reading!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以发布分析器输出的屏幕截图(即指向有问题的控制流的蓝色箭头)吗?
德普;我错过了显而易见的事情。对不起。该方法名为
newScore
,并且new*
前缀向编译器指示返回的对象是 +1 保留计数。重命名该方法,一切都会好起来的。
Can you post a screenshot of the analyzer output (i.e. the blue arrows pointing to the problematic control flow)?
Derp; I missed the obvious. Sorry. The method is named
newScore
and thenew*
prefix indicates to the compiler that the object returned is +1 retain count.Rename the method and all will be well.