-1

I wrote code that overrides object's Equals. I realized, after I wrote it, that I'm going to have StackOverFlowException since I didn't yet implemented the IEquatable interface to handle the last line of code. Yet, I run the code to see what happen, and some strange thing happen, you can see for yourself in the following image:

enter image description here

The breakpoint isn't even hittable at this moment, seems like the code is being used even before my program is run. Is it something that is done by the CLR ? Is it something else ?

Thanks for the help !

1 Answers1

2

The stack is exhausted (the very last straw that breaks camel's back) on

  if (ReferenceEquals(right, null))

probably, the stack doesn't have another 4 (8) bytes to store right. The actual reason seems to be at

  return Equals(right as Quality)

if right is of Quality type, the code is doomed to call Equals again and again

Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
  • I know where the recursive part is, it can be shown by the mark next to that line. This isn't my question. The question is why the breakpoint was missed. I would expect that even if it is an endless recursive function, I would hit the breakpoint in the first call to Equals. – Moti Berger May 11 '16 at 09:36
  • @Moti Berger: the stack is consuming, and in some point it, finally, got *exhausted*: stack can't allocate another 4/8 bytes. This final blow can occur at some random/weird point – Dmitry Bychenko May 11 '16 at 09:42
  • I understand that in an infinite recursive calling the stack eventually get exhausted, but for the exhaustion to happen, the function's code must run at least one time, so why the breakpoint wasn't hit. Something, which isn't my code, must have used the Equals function of the Quality type before my code even run ! My question is who used that function. The program crashed before it starts ! – Moti Berger May 12 '16 at 16:43