2

I don't understand why if I write these code

icons = [[NSArray alloc] initWithObjects:
             @"appointment",
             @"work",
             @"anniversary",
             @"me",
             nil];

the app crashed. But then I replaced by these code

icons = [NSArray alloc] arrayWithObjects:
             @"appointment",
             @"work",
             @"anniversary",
             @"me",
             nil];

and the app did't crash. But there is the same affect between these methods ! I don't know why ? Can u help me ?

5
  • 1
    stackoverflow.com/questions/5155097/… Commented Feb 18, 2013 at 9:10
  • 1
    provide some more code and crash logs. Commented Feb 18, 2013 at 9:12
  • Plz check this stackoverflow.com/questions/6744468/… Commented Feb 18, 2013 at 9:28
  • These methods differ by memory management. Second code gives you an autoreleased object, and if it works, you probably missed a retain call somewhere. We'd need more code to be sure, of course. Commented Feb 18, 2013 at 9:28
  • "you probably missed a retain call somewhere". I think you want to say release" instead of retain ? Yeah thank you Commented Feb 20, 2013 at 10:04

1 Answer 1

1
  1. initWithObjects method means you have to release the object of array whenever this is not required as this is instance method and for more details click:

  2. arrayWithObjects method means you don't need to release the object of array whenever this is not required as this is class method and for more details click:

If you are not clear with the points so revert me..

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

1 Comment

Thank u. I forgot release :P

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.