Is garbage collection supported for iPhone applications?

前端 未结 5 937
时光取名叫无心
时光取名叫无心 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:34

    No, garbage collection is not supported on the iPhone currently. You need to use alloc/release/autorelease.

    0 讨论(0)
  • 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!

    0 讨论(0)
  • 2020-12-05 20:40

    Note the lack of garbage collection means weak references are not supported either.

    0 讨论(0)
  • 2020-12-05 20:40

    Mono touch has garbage collection and runs on the iPhone os.

    0 讨论(0)
  • 2020-12-05 20:40

    In the entire discussion nobody says about the Java language, in Java the Garbage collection is in-built in the language so it is implicitly available in Android,J2ME and Blackberry :), where as in Objective-C it is optional, so in iPhone the GC is not available.

    0 讨论(0)
提交回复
热议问题