Is garbage collection supported for iPhone applications?

前端 未结 5 941
时光取名叫无心
时光取名叫无心 2020-12-05 20:12

Does the iPhone support garbage collection? If it does, then what are the alternate ways to perform the operations that are performaed using +alloc and -i

5条回答
  •  独厮守ぢ
    2020-12-05 20:37

    No. Garbage collection is too large an overhead for the limited battery life etc. on the device.

    You must program always with an alloc/release pattern in mind.

    NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:xmlData];
    ...
    [xmlParser release];
    

    or (not suitable for every situation)

    NSXMLParser *xmlParser [[[NSXMLParser alloc] initWithData:xmlData] autorelease];
    

    Hope this helps!

提交回复
热议问题