In objective C whenver we create any object (i.e. uiview myview), it is stored on heap. Can anybody please tell what is stored on stack?
and local variables...
ShinTakezou
2010-07-11 12:06:17
Unless it's a static local variable, or used in a closure (not sure if Objective-C has closures, but Java, C#, and now even C++ do). And even automatic variables may be in registers instead of the stack. Some calling conventions pass parameters in registers instead of on the stack, but then whatever was in the register has to be saved on the stack so it's no net difference.
Ben Voigt
2010-07-11 15:50:09
A:
Although the object may exist on the heap, the pointer that holds the object's address is on the stack.
Michael Aaron Safyan
2010-07-11 12:18:35
Or in a register. Or in another object on the heap. People are always over-simplifying this.
Ben Voigt
2010-07-11 15:51:09
@Ben, yes, it is of course possible to allocate a pointer on the heap. I was trying to explain, particularly in the context of Objective-C, how, despite everything being accessed through pointers, there are still objects on the stack. Your answer was very good and is an answer that applies to all languages. I figured I would supplement it with information about the language in question.
Michael Aaron Safyan
2010-07-11 16:54:17