Some beginner Objective-C/iPhone questions

前端 未结 5 489
终归单人心
终归单人心 2020-12-31 21:01

I\'m just starting out (reading up a lot for the past couple of days). Here\'s some questions that I have stacked up, hopefully someone can answer them.

1.

5条回答
  •  -上瘾入骨i
    2020-12-31 21:06

    1. If self is nil after the super initialisation then you're probably out of memory. Your only reasonable course of action is to return nil and hope things get handled gracefully further up the stack.

    2. Static methods aren't allowed allocate on the heap, therefore there's nothing to free.

    3. In the first instance, the string is compiled into the data segment of your app and cannot be freed. In the second instance, you are allocating memory from the heap and copying your static string (from the data segment) into it.

    4. It's simple garbage collection. As to why to use it, the simple answer is don't. It's not recommended to use autorelease on the iPhone due to limited resources.

提交回复
热议问题