Aleem
Aleem

Reputation: 3291

Memory management in Objective c

  1. I am new in objective c and also in development field, and i want to know that when we quit our application then os automatically release or finish our resources that we retain during our application so why we need to do it explicitly(release or autorelease in obj c)?

  2. My second question is that i am facing problem in when i release object of app delegate class in rootViewcontroller class in dealloc method then my program is crash when again i am going to go in controller class like follwing.

    -(void) viewDidLoad { TestAppDelegate * object = (TestAppDelegate *)[[UIApplication sharedApplication]delegate]; }

    -(void)dealloc {[object release]; [super dealloc];}

Upvotes: 0

Views: 124

Answers (1)

Jurlie
Jurlie

Reputation: 1014

  1. You should release or autorelease objects in order to make all the objects execute their -()dealloc's. When process finishes OS clears all the memory occupied by process but it cannot clear some other resources (mutexes, semaphores, maybe something else) because they are kernel objects and might be used by different processes. So OS cannot know whether to delete these objects as initial process finished. Developer should clear such objects himself and this is done usually in dealloc methods of proper objects.

  2. It's not clear when crash happens. Could you clarify?

Upvotes: 2

Related Questions