Objective C: Memory Allocation on stack vs. heap

前端 未结 4 1399
误落风尘
误落风尘 2020-12-08 08:28

I am somewhat confused about when things are allocated on the heap (and I need to release them) and when they are allocated on the stack (and I don\'t need to relese them).

4条回答
  •  星月不相逢
    2020-12-08 08:33

    There are no stack allocations of objects in Objective-C (Blocks are a different case that I'm not going to get into here)

    NSString *user = @"DEFAULT";
    

    That allocates a NSConstantString object in constant memory, not on the stack.

提交回复
热议问题