Hi,
I have a function in a Dao class which return an Array. I get array from that function and used it in another class but when I release that array, the application crash when I run it.
Here is my code:
Dao.m
//Funtion to get data from database and return an NSMutableArray.
-(NSMutableArray*) selectTypesArray
{
NSMutableArray * types = [NSMutableArray alloc]init];
// Some code here to get data from database.
return types;
}
FirstViewController.m
viewDidLoad
{
Dao dao = [[Dao alloc]init];
NSMutableArray * temp = [dao selectTypesArray];
NSMutableArray * types = temp;
[self.displayTypes:types];
[temp release];
[dao release];
}
-(void)displayTypes: (NSMutableArray*)types
{
NSLog(@"Types count %i", [types count]);
}
When I run the program, it crash with the error message : "-[__NSArrayM count]: message sent to deallocated". I think that this happens is because I have released "temp" and "types" reference to an deallocated object ... ...But I don't know how to write this code in a correct way. Anyone can tell me the correct way to write this code?
Any comments and suggestions are welcome and appreciated. Thanks a lot.
I have a function in a Dao class which return an Array. I get array from that function and used it in another class but when I release that array, the application crash when I run it.
Here is my code:
Dao.m
//Funtion to get data from database and return an NSMutableArray.
-(NSMutableArray*) selectTypesArray
{
NSMutableArray * types = [NSMutableArray alloc]init];
// Some code here to get data from database.
return types;
}
FirstViewController.m
viewDidLoad
{
Dao dao = [[Dao alloc]init];
NSMutableArray * temp = [dao selectTypesArray];
NSMutableArray * types = temp;
[self.displayTypes:types];
[temp release];
[dao release];
}
-(void)displayTypes: (NSMutableArray*)types
{
NSLog(@"Types count %i", [types count]);
}
When I run the program, it crash with the error message : "-[__NSArrayM count]: message sent to deallocated". I think that this happens is because I have released "temp" and "types" reference to an deallocated object ... ...But I don't know how to write this code in a correct way. Anyone can tell me the correct way to write this code?
Any comments and suggestions are welcome and appreciated. Thanks a lot.