TheLearner
TheLearner

Reputation: 19507

I only release objects if I create them using alloc?

According to Apple if one doesn't create an object using alloc or new then it does not need to be released.

Is my understanding correct? So something like this does not need to be released:

NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30];

Upvotes: 0

Views: 103

Answers (3)

Jacob Relkin
Jacob Relkin

Reputation: 163318

If a method name contains new, alloc, or copy, you must release it.

You do not need to release the NSURLRequest in your example, it is autoreleased.

Upvotes: 1

Nikolai Ruhe
Nikolai Ruhe

Reputation: 81878

Apple`s Memory Management Rules:

You take ownership of an object if you create it using a method whose name begins with “alloc” or “new” or contains “copy”

So: You are right.

Upvotes: 2

Cromulent
Cromulent

Reputation: 3828

Correct. You would not release that object. The only time you would is if you had first retained it (i.e taken ownership of it).

Upvotes: 0

Related Questions