内存泄漏问题,我需要帮助#1 [英] Memory leak problem and i need help #1

查看:118
本文介绍了内存泄漏问题,我需要帮助#1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的这个,似乎有一个泄漏在这段代码,我不能修复:

I am very new at this and seems to have a leak in this piece of code that i cannot fix:

仪器显示在这一行与一个100% :

The Instruments shows on this line with a 100%:


NSMutableArray * read_Question = [[NSMutableArray alloc] initWithCapacity:0];

NSMutableArray *read_Question = [[NSMutableArray alloc] initWithCapacity: 0];

我已经尝试过所有类型的事情,但无法解决它。

I have tried all kind of things but not been able to fix it.

任何人都可以告诉我如何继续?

Anyone nice that can advice me how to proceed?

- (NSMutableArray *)readQuestion: (int)questionNr {

NSMutableArray *read_Question = [[NSMutableArray alloc] initWithCapacity: 0];

NSError *error;
//=========PREPARE CORE DATA DB===========//
if (managedObjectContext == nil) {
    managedObjectContext = [(FamQuiz_R0_1AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; }
    // Define qContext
    NSManagedObjectContext *qContext = [self managedObjectContext];
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"questions" inManagedObjectContext:qContext];
    [fetchRequest setEntity:entity];

    NSArray *fetchedObjects = [qContext executeFetchRequest:fetchRequest error:&error];
    for (NSManagedObject *info in fetchedObjects) {
        if ([[info valueForKey:@"idQ"] intValue] == questionNr) { 
            [read_Question addObject:[info valueForKey:@"question"]];
            [read_Question addObject:[info valueForKey:@"qRightAnswer"]];
            [read_Question addObject:[info valueForKey:@"qWrongAnswer1"]];
            [read_Question addObject:[info valueForKey:@"qWrongAnswer2"]];
        }
    }   
    [fetchRequest release];
    return [read_Question autorelease];
}


推荐答案

其他问题内存泄漏问题,我需要帮助#1


当我发布我有麻烦,
当然。我试着改变三个
的名字,然后释放,所以
有唯一的名字,但是
不起作用。

When i did release i got into trouble, of course. I did try to change the names on the three and do release so there was unique names but that did not work.

更改三个不同文件的名称?这不会做任何事情,它表明你没有完全包裹你的头围绕对象,指针和内存管理。

Changing the names across three different files? That won't do anything and it indicates that you haven't entirely wrapped your head around objects, pointers, and memory management.

Objective-C 内存管理指南将有所帮助。


这可能是这个.m文件中泄露
i的原因吗?

Could this be the reason for the leak i have in this .m file?

不 - 如我在另一个问题中回答,泄漏很可能是因为您保留了该方法返回的对象然后不要在任何地方释放它。

Nope -- as I answered in the other question, the leak is most likely because you retain the object that is returned by that method and then don't release it anywhere.

这篇关于内存泄漏问题,我需要帮助#1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆