5

What is the differece between:

[[NSMutableArray alloc] init]

and

[NSMutableArray array]
1

4 Answers 4

12

Here in [NSMutableArray array] you don't have to release array it will be released automatically. & if you will write [NSMutableArray alloc] init] you will have to release array so [[NSMutableArray array] will be equivalent to [[[NSArray alloc] init] autorelease];

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

1 Comment

I edit this , ImageList = [[NSMutableArray alloc] init]; as ImageList = [[[NSMutableArray alloc] init] autorelese] ; but it didn't work. What should be the error
1

The first remains in memory until you release it, the second lasts until the end of the run loop iteration.

Comments

1

NSMutableArray no need to release memory and [NSMutableArray alloc] init] u must be release it.

Comments

0

when ARC does work, you have to release objects come from methods including init,alloc,new,copy and mutableCopy, like [NSMutableArray alloc] init]. If not, the objects will be registered to autoreleasepool, like [NSMutableArray array].

Comments

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.