1

I'm assuming the definition of alloc goes along the lines of:

Locates and allocates a block of memory for an object

And the definition init goes something like:

Creates an object in the newly allocated memory block

I'm just trying to wrap my head around more regarding memory management and want to make sure that I'm getting this right..

2
  • 1
    So what's your question? :) Commented Mar 25, 2014 at 20:56
  • [NSObject alloc] Commented Mar 25, 2014 at 20:57

1 Answer 1

1

That is sort of right.

It is right in principle. But init is actually not required to return the same, indentical, object. I never observed this (well, frankly, never checked for it either) but theoretically init may release the allocated object, allocate another one, initialize the second and return a refernce to the second one. Besides that detail you are totally right.

Sign up to request clarification or add additional context in comments.

2 Comments

Want to see different objects from init? Take a look at NSArray, NSString, NSDictionary…
I thought there must be some. There must be a reason for that. Thanks @Chuck, I'll keep an eye on alloc/init of those types.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.