Help ! Memory Management Problem.


hi,

newbie of develop iphone application. quite confuse memory management when using objects in application.

here code:

(i have cardao class access database; car entity has attribute named carname).
code:
 -(void)displaycar {     cardao * dao = [[cardao alloc]init];          //select cars database.     [color="blue"]nsmutablearray * cars = [dao selectallcars];  [/color]           if ([cars count]>0)      {          (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]; } 
but, when trace memory leaks using instruments. shows leaked blocks. these leaked blocks caused code in blue color shown in above. i'm quite confuse because release "car" , "dao" @ end of code why memory problem still exists. or doing wrong in code. can tell me? or can show me correct way write code? comments , suggestions welcome.

lot help. :)
 

you're creating new car object, on next line you're assigning pointer different object, car object created has no pointer it. dont send alloc init message new car, send objectatindex instead.
 


Forums iPhone, iPad, and iPod Touch iOS Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

Comments

Popular posts from this blog

Mac OS X Server as File Server for 50/50 Mac & PC Workgroup

Permissions Problem?

iPhone won't sync with iTunes