5

What is the differece between:

[[NSMutableArray alloc] init]

and

[NSMutableArray array]
susitha
  • 467
  • 3
  • 9
  • 16
  • 5
    possible duplicate of [Diference between \[NSMutableArray array\] vs \[\[NSMutableArray alloc\] init\]](http://stackoverflow.com/questions/5423211/diference-between-nsmutablearray-array-vs-nsmutablearray-alloc-init) – kennytm Dec 19 '11 at 04:48

4 Answers4

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];

Girish
  • 4,692
  • 4
  • 35
  • 55
Aakil Ladhani
  • 984
  • 9
  • 32
  • I edit this , ImageList = [[NSMutableArray alloc] init]; as ImageList = [[[NSMutableArray alloc] init] autorelese] ; but it didn't work. What should be the error – susitha Dec 19 '11 at 05:03
1

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

Nico
  • 3,826
  • 1
  • 21
  • 31
1

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

Girish
  • 4,692
  • 4
  • 35
  • 55
Ravi Kumar Karunanithi
  • 2,151
  • 2
  • 19
  • 41
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].

holybiner
  • 61
  • 2