When you compile for profiling, the compiler does optimizations. One of those optimizations is dead-store optimization:
num = NULL; // The optimizer deleted this operation
Normally, why would you care if num
actually equals NULL
? Since you never read the value of num
, you have no way of knowing if the compiler actually stored NULL
there without looking at the assembly output. So the compiler doesn't bother actually writing NULL
to that location.
But wait, there's more
I did a test:
#include <unistd.h>
int main()
{
int *num = new int[100];
num[4] = 5;
num = NULL;
sleep(1);
return 0;
}
The assembly (prologue and epilogue omitted for brevity):
movl $1, %edi
callq _sleep
xorl %eax, %eax
Wait a darn minute, what happened to new int[100]
and num[4] = 5
?
The entire allocation got optimized out, because the compiler figured out a way to get the same result without allocating anything. Compilers are amazing, aren't they?