*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.
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"
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.
精彩评论