UILabel的文本设置分析奇怪的内存泄漏

发布于 2024-11-26 08:34:15 字数 602 浏览 2 评论 0原文

当我产品>时分析 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;

testViewUIView 的子类。

编辑:分析器输出的屏幕截图: 在此处输入图像描述

感谢您的阅读!

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:
enter image description here

Thank you for reading!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

锦爱 2024-12-03 08:34:15

您可以发布分析器输出的屏幕截图(即指向有问题的控制流的蓝色箭头)吗?


德普;我错过了显而易见的事情。对不起。该方法名为 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 the new* prefix indicates to the compiler that the object returned is +1 retain count.

Rename the method and all will be well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文