开发者

Stack and heap issue for iPhone memory management

开发者 https://www.devze.com 2023-02-01 17:43 出处:网络
*Why are all objects in Objective-C allocat开发者_运维技巧ed in the heap instead of on the stack?

*Why are all objects in Objective-C allocat开发者_运维技巧ed in the heap instead of on the stack?

How about if we program with both Objective-C and C++?


It isn't clear what you are asking.

If you are asking about things like NSString* str = @"hello";, then that was answered in the question you linked to.

Why there is no heap? doesn't make sense. There very much is a heap in iOS applications and objects are allocated from it.

The mention of "automatic objects" and/or auto_ptr from the "post" you mention is entirely unrelated to Objective-C.

Clarify your question, please.


  1. All Object C objects should be alloc in stack ? ( I think yes )

    No. As the quote in your question says, "the Objective-C runtime does not allow objects to be instantiated on the stack"

  2. In C++, there are stack for memory, so for iOS app, also have stack ? ( I think yes )

    Yes, there is a stack in Objective-C. Objects simply aren't allocated there.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号