Ok some progress, now we are on the same page talking about the entire stack and the objects currently referenced from it and not some object that at some point in the past was on that stack.If you call gc_collect(), the correct stack is correctly taken into account so your entire first example is incorrect.
Now next step : explain to me how a [1] stack that is not in the GC heap can possibly [2] be taken into account ?
There are 2 parts in that sentence , which one(s) are you contesting so we can further elaborate ...
[1] That it is not in the GC heap ? -> In that case do you understand how eg linker files work ? Where the stack comes from that 'main' is executed in ? It exists before gc_init is called so there is no way it can be in the gc heap.
[2] That is not taken into account ? It is not because of the VERIFY_PTR macro which as you already said yourself will not further look at anything that is not in the heap.
I keep repeating the same things over and over, please take some time to understand what i am saying here. I have a problem that I can see when stepping in the debugger, that I understand from the code, and that I know how to fix in the code. At this point I am 99.9% sure that I am *right*.
Remark:
And I don't know what you mean by 'correct' stack. To elaborate:
- There is no correct stack, all the stacks need to be taken into account (which is done in mp_thread_gc_others )
- There is however a correct part of the stack, which would be the part between the current stack pointer and the top of the stack. As I already explained, this is NOT taken into account correctly. And attempt is made to do it for the stack calling gc_collect, but it is then 'redone' when the mp_thread_gc_others function is called where the entire stack will be checked anyway via gc_collect_root((void**)&th, 1);