-(void)LoadOriginalListFromFile
{
NSMutableArray *temp;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"shopes.dat"];
//2.check if file exists
NSFileManager *fileManager = [NSFileManager defaultManager];
if([fileManager fileExistsAtPath:path])
{
//open it and read it
NSLog(@"shopes.dat file found. reading into memory");
NSMutableData *theData;
NSKeyedUnarchiver *decoder;
//3. decode the file into memory
theData = [NSData dataWithContentsOfFile:path];
decoder = [[NSKeyedUnarchiver alloc] initForReadingWithData:theData];
temp = [[NSMutableArray alloc]init];
temp = [decoder decodeObjectForKey:@"m_OriginalArray"];
//4. add object to original list
NSEnumerator *enumerator = [temp objectEnumerator];
id anObject;
while (anObject = [enumerator nextObject])
{
[m_OriginalArray addObject:anObject];
}
//[temp release]; // here is the problem!!!!!
[decoder finishDecoding];
[decoder release];
}
else
{
NSLog(@"shopes.dat file not found");
}
}
I have problem with the temp object. what i want to do is to release the object before the function end but if i do so when the app is launch i get ERROR_BAD_ACSS , i cant understand why? i alloc the temp object then i add all the objects in the temp array to my m_OriginalArray i also tryied to retain the objects but no lack.