stack and heap issue for iPhone memory management

Posted by Forrest on Stack Overflow See other posts from Stack Overflow or by Forrest
Published on 2010-12-25T05:26:43Z Indexed on 2010/12/25 9:54 UTC
Read the original article Hit count: 492

From this post I got know that

the Objective-C runtime does not allow objects to be instantiated on the stack, but only on the heap; this means that you don’t have “automatic objects”, nor things like auto_ptr objects to help you manage memory;

Someone give one example in post Objective C: Memory Allocation on stack vs. heap

NSString* str = @"hello";

but this NSString is also not allocated in stack. Feel odd that this str is static. (Who can explain this ? )

Question here is that why there is no heap ? even mixing c++ together with Object C ?

/////////////////////////////// Clear my question ///////////////////////////////

I am confused , so questions are not clear. Let me put in this way.

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

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

3) for iOS app, if only use Object C, so what is the usage of stack ? what kind of objects should use stack then ?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c