Why do Objective-C objects have to be dynamically allocated?
问题 Why do Objective-c objects have to be dynamically allocated? Why do I have to make it a pointer to an object, unlike in C++ I can create them on stack? Thanks. 回答1: the primary reason: not knowing how much stack size to reserve. existing conventions and uses also make lifting the restriction quite difficult. dynamic messaging does not matter in this case, as setting the right 'vtable' at initialization is trivial. in c++, the size of a stack object is always known (and if it's wrong, you know