Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cthesky

macrumors member
Original poster
Aug 21, 2011
91
0
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. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.