I have a crash problem when I am trying to add object into array, I think I have problem with the way i create object and release it. But I am not quite sure cause I am still kinda weak with memory management
NSMutableDictionary *schools = [[NSMutableDictionary alloc] init];
[schools setObject:name forKey:kFavoriteSchoolName];
//load data is getting data from NSUserDefault which I save
NSMutableArray *loadedArray = [self loadData];
//if loadedarray has object in there, then continue adding schools to it or make new array
if([loadedArray count] > 0)
{
[loadedArray addObject:schools];
> // it crashes here
[schools release];
return loadedArray;
} else
{
//It will add the school to the array for the first time if there is nothing when it loaded.
NSMutableArray *tempArray = [[[NSMutableArray alloc] init] autorelease];
[tempArray addObject:schools];
[schools release];
return tempArray;
}
This function help add the school into favorite list. I cant add once, but it crashes when I add it again.
This is my code of loadData function
- (NSMutableArray *) loadData
{
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
NSMutableArray *list = [userDefault objectForKey:kSchoolList];
return list;
}
The log does not say anything but this: Thread 1: Program received signal "SGABRT"
when I first run the programme and add, it is fine, I add school again then only it crashes, crashes at [loadedArray addobject:schools];
[self loadData]is mutable too...other wise do this and try againNSMutableArray *loadedArray = [[self loadData]mutable copy];