Hi,
I am newbie of develop Iphone Application. I am quite confuse with the memory management when using objects in my application.
Here is my code:
(I have a CarDao class to access database; a car entity which has a attribute named as carName).
But, when I trace the memory leaks by using the instruments. It shows the leaked blocks. These leaked blocks is caused by the code in blue color as shown in above. I'm quite confuse because I already release the "car" and "dao" at the end of code but why the memory problem still exists. Or am I doing something wrong in my code. Can someone tell me? Or can someone show me the correct way to write this code? Any comments and suggestions are welcome.
Thanks a lot for your help.
I am newbie of develop Iphone Application. I am quite confuse with the memory management when using objects in my application.
Here is my code:
(I have a CarDao class to access database; a car entity which has a attribute named as carName).
Code:
-(void)displayCar
{
CarDao * dao = [[CarDao alloc]init];
//Select all cars from database.
[COLOR="Blue"]NSMutableArray * cars = [dao selectAllCars]; [/COLOR]
if ([cars count]>0)
{
for (int i=0; i<[cars count]; i++)
{
[COLOR="Blue"]Car * car = [[Car alloc]init];[/COLOR]
car = [cars objectAtIndex:i];
if (car != nil)
{
NSString * carName = car.carName;
NSLog(@"Car name %@ ", carName);
}
[car release];
}
}
[dao release];
}
Thanks a lot for your help.
Last edited: