Stanley
Stanley

Reputation: 4486

Why dealloc is not called?

I am writing some test code on Cocoa. Have put the AppController object in IB. An NSMutableArray is declared and initialized in the AppController. Everything runs ok, as users can input to the array and its content is displayed on a NSTableView etc.

Then I add a - (void) dealloc {} method to the AppController. My question is : why is it not being called at all when the program is terminated by pressing the "red tasks" button? Just that I wish to explicitly free the memory associated with the array before the program ends. And do I need to explicitly free the array ? (no Garbage Collection)

Upvotes: 0

Views: 382

Answers (2)

Catfish_Man
Catfish_Man

Reputation: 41801

Memory is not freed when a program terminates, since all memory associated with the process is automatically bulk-freed when it dies anyway. If you need to do non-memory related cleanup at termination time, use NSApp's delegate method -applicationWillTerminate:

Upvotes: 3

BoltClock
BoltClock

Reputation: 723398

When the program ends execution, it doesn't need to occupy any memory space anymore. The OS will automatically destroy the process associated with the program and reclaim whatever memory it had occupied in its lifespan. So whether you explicitly deallocate or not just as the program terminates doesn't matter.

Upvotes: 2

Related Questions