螺纹内漏
好的...大家好,我无法解决这个问题。我的代码中有大量泄漏,但我不明白为什么。
首先你应该知道,这段代码是在后台运行的,所以我为它创建了一个自动释放池。嗯,说实话,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧好吧,谢谢所有尝试过查看它的人。
问题是我没有释放实例变量,并且 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