TechChain
TechChain

Reputation: 8944

Confusion in memory management in Objective-C?

I read about manual & ARC memory management in Objective-C. In below points I am confused which is true about memory management in Objective-C?

Upvotes: 1

Views: 108

Answers (3)

Brett Donald
Brett Donald

Reputation: 14122

Just use ARC and happy days!

However, you should at least be aware of the difference between strong and weak references.

Upvotes: 0

Dancreek
Dancreek

Reputation: 9544

There isn't much reason to use manual memory management in most cases anymore.

But to answer your question, don't nil in dealloc. Instead:

  1. Do nothing with properties in dealloc with ARC.
  2. release strongly held properties in dealloc in manual management. [myObject release];

Upvotes: 1

Alexander
Alexander

Reputation: 63157

You never have to "nil" out properties, you just have to release them when doing manual memory management.

When you set a value to nil, you lose track of the old value that was there. That old value stored the address of the object. Now that object continues to exist, but you no longer know its address, and have no way of releasing it.

Release tells an object "I'm no longer using you, and if I'm the last one, then delete yourself". In ARC, retain and release calls are added automatically by the compiler. There's rarely any reason to do that manual memory management yourself anymore. ARC is the way to go.

Upvotes: 1

Related Questions