Can i release an object (created in a method) in another method (without retaining) in objective C ?
My code is as follows
-(NSMutableDictionary *)returnningMyMutableDictionary{
NSMutableDictionary *myDict = [[NSMutableDictionary alloc] init];
[myDict setObject:@"My Name" forKey:@"name"];
[myDict setObject:@"99" forKey:@"age"];
return myDict;
}
-(void)mainmethod{
NSMutableDictionary *dict = [self returnningMyMutableDictionary];
NSLog(@"dict %@",dict); dict = nil; [dict release];
}
Q1) Is it good practice to release the returning dictionary in "mainmethod" ?
Q2) When i run the application in instrument , i am getting leak in following portion.
[myDict setObject:@"My Name" forKey:@"name"];
How to avoid memory leak here ?
Please help me..Thanks in advance for your help..