在我TaggingScreen.m初始化函数,我做的 -iOS的 - 无法删除内存泄漏
tags = [myTagMgr getMyTags];
在我getMyTags的方法,我做以下 -
NSMutableDictionary *myTags = [NSMutableDictionary new];
....
return myTags;
我得到了内存泄漏对于这种方法中的myTags。我应该在哪里释放内存? “标签”是整个TaggingScreen类中使用的属性。因此,如果我执行autorelease,当我尝试访问该类的其他方法中的标记时,会收到一条异常,指出“发送到释放实例的消息”。
编辑:
- (NSMutableDictionary *)getMyTags
{
NSMutableDictionary *myTags=[NSMutableDictionary new];
NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init]autorelease];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Tag"
inManagedObjectContext:localObjectContext];
[fetchRequest setEntity:entity];
NSError *error = nil;
NSArray *fetchedArrayObjects = [localObjectContext executeFetchRequest:fetchRequest error:&error];
if (fetchedArrayObjects ==nil) {
return nil;
}
if ([fetchedArrayObjects count]==0) {
return nil;
}
Tag *aMessage;
for (int i=0; i<[fetchedArrayObjects count];i++)
{
aMessage= (Tag *)[fetchedArrayObjects objectAtIndex:(NSUInteger)i];
[myTags setValue:[aMessage isSet] forKey:[aMessage tagName]];
}
return myTags;
}
什么样的@属性是'tags'? – yuji 2012-03-27 16:09:22
它的一个@property(nonatomic,assign)NSMutableDictionary *标签; – Suchi 2012-03-27 16:14:02