螺纹内漏

发布于 2024-11-03 04:42:08 字数 1274 浏览 6 评论 0原文

好的...大家好,我无法解决这个问题。我的代码中有大量泄漏,但我不明白为什么。

首先你应该知道,这段代码是在后台运行的,所以我为它创建了一个自动释放池。嗯,说实话,MBprogressHUD 适合我。

代码可以工作,但是 Instruments 说我在 diccionario 的创建(alloc/init)、temporal 数组的创建、temporalMutable 数组的创建等方面存在一些泄漏。几乎每一段执行 alloc/autorelease 的代码都会出现泄漏。

有什么想法吗?

// Some more code at the beginning

NSMutableDictionary *diccionario=[[NSMutableDictionary alloc] init];    

for (Horas *hora in [dia oraciones]) {

    if ([diccionario objectForKey:[hora Tipo]]==nil)
    {
        NSArray *temporal=[NSArray arrayWithObjects:[hora Hora],[hora Texto], nil];
        NSMutableArray *temporalMutable=[NSMutableArray arrayWithObjects:temporal, nil];
        [diccionario setObject:temporalMutable forKey:[hora Tipo]];

    }
    else
    {           
        NSMutableArray *nuevo=[diccionario objectForKey:[hora Tipo]];
        NSArray *temporal=[NSArray arrayWithObjects:[hora Hora],[hora Texto], nil];
        [nuevo addObject:temporal];
        [diccionario setObject:nuevo
                        forKey:[hora Tipo]];
    }

}

MyClass *resultado=[[[MyClass alloc] initSinDescarga:fecha tituloDia:[dia titulo] celebracionDia:[dia celebracion] oracionesDia:diccionario] autorelease];
[diccionario release];
return resultado;

}

Ok... Hello everybody I have not been able to solve this one. I have TONS of leaks inside my code and I cannot figure out why.

First you should know, this code is running in background, so I create a autorelease pool for it. Well, to be honest, MBprogressHUD does for me.

The code works, but Instruments says I have some leaks in the creation (alloc/init) of diccionario, creation of temporal array, creation of temporalMutable array, etc. Almost every piece of code that does any alloc/autorelease gets a leak.

Any ideas?

// Some more code at the beginning

NSMutableDictionary *diccionario=[[NSMutableDictionary alloc] init];    

for (Horas *hora in [dia oraciones]) {

    if ([diccionario objectForKey:[hora Tipo]]==nil)
    {
        NSArray *temporal=[NSArray arrayWithObjects:[hora Hora],[hora Texto], nil];
        NSMutableArray *temporalMutable=[NSMutableArray arrayWithObjects:temporal, nil];
        [diccionario setObject:temporalMutable forKey:[hora Tipo]];

    }
    else
    {           
        NSMutableArray *nuevo=[diccionario objectForKey:[hora Tipo]];
        NSArray *temporal=[NSArray arrayWithObjects:[hora Hora],[hora Texto], nil];
        [nuevo addObject:temporal];
        [diccionario setObject:nuevo
                        forKey:[hora Tipo]];
    }

}

MyClass *resultado=[[[MyClass alloc] initSinDescarga:fecha tituloDia:[dia titulo] celebracionDia:[dia celebracion] oracionesDia:diccionario] autorelease];
[diccionario release];
return resultado;

}

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

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

发布评论

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

评论(1

橪书 2024-11-10 04:42:08

好吧好吧,谢谢所有尝试过查看它的人。

问题是我没有释放实例变量,并且 Instruments 指出了内存分配的泄漏而不是泄漏的地方......所以......我很困惑。

再次感谢

Ok Ok Thanks no everyone who has tried to have a look at it.

The problem is that I was NOT releasing an instance variable, and Instruments points a leak where the memory is allocated NOT where it is leaked... So... I was confused.

Thanks again

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