this is my code:
array = [[NSMutableArray alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//make a file name to write the data to using the
//documents directory:
NSString *fullFileName = [NSString stringWithFormat:@"%@/file", documentsDirectory];
array = [NSKeyedUnarchiver unarchiveObjectWithFile:fullFileName];
What’s Wrong in my code?
This is the error
[__NSArrayM count]: message sent to deallocated instance 0xd5864e0
The statement
will give you back an autorelease object that will be deallocated at the first appropriate moment. So, when you later access its
countmethod, the object is not there anymore. This is what is causing the crash.A way to fix this is properly managing your array so that it stays there as long as you need it. If you are using ARC, this could mean managing the object through a
strongproperty; if you are not using ARC, this involves usingretain. You do not specify howarrayis declared so I cannot be more precise.Since you say that the property is declared as:
simply doing:
should fix the problem.