0

*Why are all objects in Objective-C allocated in the heap instead of on the stack?

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

trincot
  • 317,000
  • 35
  • 244
  • 286
Forrest
  • 122,703
  • 20
  • 73
  • 107

2 Answers2

3

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.

bbum
  • 162,346
  • 23
  • 271
  • 359
1
  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.

Chuck
  • 234,037
  • 30
  • 302
  • 389