从 NSDictionary 泄漏

发布于 2024-11-14 08:16:03 字数 735 浏览 2 评论 0原文

我有莫名其妙的泄漏。 LEAKS 告诉我下面指示的线路正在泄漏。 我是在转述,但很忠实。它从文件中提取 NSDictionary,然后将其发送到另一个进程。
据我所知,所有这些对象的内存都应该由操作系统管理。

我不知道 LEAKS 是如何工作的,但我猜它标志着操作系统想要释放“statusdict”但不能释放的点,因为其中有一些未释放的东西。但其中没有任何内容不是通过此处所示的过程获得的。


NSDictionary *statusdict = [self readStatus];

[self runProcess:[statusdict objectForKey:@"objectname"]];  <- it leaks here


-(NSDictionary*) readStatus {

    NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

    NSString *status = [[docPath stringByAppendingPathComponent:@"status.plist"] retain];

    cstat = [NSDictionary dictionaryWithContentsOfFile:status];

    [status release];


    return (cstat);

}

I'm having a baffling leak. LEAKS tells me that the line indicated below is leaking.
I'm paraphrasing, but faithfully. It pulls an NSDictionary from a file, then sends it off to another process.
As far as I know, the memory for all of these objects should be managed by the OS.

I don't know how LEAKS works, but I'm guessing it's marking the point where the OS wants to release "statusdict" but can't because there's something unlereased within it. But there's nothing in it that wasn't acquired by the process shown here.


NSDictionary *statusdict = [self readStatus];

[self runProcess:[statusdict objectForKey:@"objectname"]];  <- it leaks here


-(NSDictionary*) readStatus {

    NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

    NSString *status = [[docPath stringByAppendingPathComponent:@"status.plist"] retain];

    cstat = [NSDictionary dictionaryWithContentsOfFile:status];

    [status release];


    return (cstat);

}

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

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

发布评论

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

评论(1

意犹 2024-11-21 08:16:03

当对象保留的时间多于释放的时间时,就会发生泄漏。系统不会自动释放任何东西。您可以手动释放它,也可以自动释放它。

我无法从这段代码中看出你的泄漏在哪里,尽管我猜测是 runProcess 方法。

但找到这个漏洞并不能解决你的问题。你需要了解iOS内存管理。

从这里开始:

A leak occurs when an object is retained more than it's released. The system doesn't automatically release of anything. You either release it manually, or autorelease it.

I can't tell where your leak is from this code, though my guess is the runProcess method.

But finding this leak won't solve your problem. You need to understand iOS memory management.

Start here:

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