在我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