In an objective C project with GC enabled, I am allocating an array of variable size on the stack like this:
MaValue *myStack = alloca((sizeof(id) * someLength));
(The reason why I want to do this is not important:) Then, within a loop, I push and pop stuff on/from myStack. Some of the things I push onto the stack are new objects that are not referenced from anywhere else.
My gut feeling tells me, that the objective C garbage collector doesn't know about those pointers and therefore would collect the new (otherwise unreferenced) objects. Part of that believe comes from the thought, that the objective C GC isn't really conservative but "knows its pointers" (e.g., through a stack map).
However, in all my experiments (inserting [[NSGarbageCollector defaultCollector] collectExhaustively] calls) I didn't get those objects to be collected – which is good, but unexpected. So it seems, that the GC is scanning the whole stack and, for example, conservatively assumes an integer that happens to have the value of a valid pointer to really be a pointer.
Is that correct? Or am I missing something?