苹果框架内存泄漏

发布于 2024-12-08 01:15:52 字数 600 浏览 0 评论 0原文

当我发布我的类时,我收到了 NSStrings 的泄漏。但我的属性中只有 2 个 NSString 。我在此类的方法中使用了其他 NSString,并在退出该方法之前释放它们。

[somestring release],somestring = nil;

这是屏幕截图

在此处输入图像描述

这是我的问题吗?或者这个泄漏属于苹果框架?我还在课堂上使用 ASIHTTPRequest。

编辑:我发现了问题。我使用了几次 NSMutableArray 和 mutableCopy 方法,没有自动释放。

之前和有泄漏: someMutableArray = [anotherClass.anotherMutableArray mutableCopy];

之后,并且没有泄漏: someMutableArray = [[anotherClass.anotherMutableArray mutableCopy]autoreleasing];

When i release my class, i receive leaks with NSStrings. But i have only 2 NSString in properties. Other NSString I use in my methods in this class, and i release them before exit from the method.

[somestring release],somestring = nil;

Here is screenshot

enter image description here

Is it my problem? Or this leaks belongs to apple frameworks? I also use ASIHTTPRequest in my class.

EDIT: I found the problem. I used few times NSMutableArray and mutableCopy method, without autoreleasing.

Before, and with leaks: someMutableArray = [anotherClass.anotherMutableArray mutableCopy];

After, and without leaks: someMutableArray = [[anotherClass.anotherMutableArray mutableCopy]autoreleasing];

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

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

发布评论

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

评论(3

殊姿 2024-12-15 01:15:52

苹果的框架可能不会泄露。

如果您将该变量传递给另一个对象,并且另一个对象保留该变量而不释放,您将看到泄漏。它似乎是您分配字符串的位置,而不是在第二个对象中。

内存泄漏是我放弃 ASIHTTPRequest 的原因。我知道它来自 ASIHTTPRequest,但无法找出位置。

在这种情况下,您能做的最好的事情可能就是查看泄漏块之一的块历史记录。您将看到各种保留和释放。他们应该保持平衡;此外,每个保留都应该有一个与其对应的释放。例如,如果您在对象 setter 中看到对象的保留,则应验证该 setter 中是否已释放前一个对象,并且 dealloc 中是否有释放。尝试识别泄漏的最高级别对象,因为其他泄漏可能是它的成员变量。

Apple's frameworks are probably not leaking.

If you pass that variable to another object and that other object retains it without releasing, you'll see a leak. And it'll appear to be where you allocated the string, rather than in the second object.

Memory leaks are why I gave up on ASIHTTPRequest. I knew enough to know it was coming from ASIHTTPRequest, but wasn't able to find out where.

Probably the best thing you can do in this case is look at the block history for one of the leaked blocks. You'll see various retains and releases. They should balance; more, each retain should have a release it its counterpart. For instance, if you see a retain of an object in an object setter, you should verify that the previous object was released in that setter and there's a release in the dealloc. Try to identify the highest level object that's leaking, as the other leaks are probably member variables of it.

深海不蓝 2024-12-15 01:15:52

在乐器中,左侧有一个名为“调用树”的部分。当您选中“隐藏系统库”时,只会显示您的方法调用。您应该尝试一下,看看您自己的代码是否与泄漏有关。

In instruments, there's a section named Call Tree at the left hand side. When you check Hide System Libraries, then only your method calls show up. You should try this to see if your own code has anything to do with the leaks.

烟若柳尘 2024-12-15 01:15:52

您需要在dealloc方法中释放变量。

You need to release the variables in the dealloc method.

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