Why would you expect to print 1, if you increase x by 1 (to 2) before you call that anonymous procedure? At the moment the procedure is called the value of x is 2.
First you call TestNested, which does:
- set 1 to x
- set some procedure as result
- increase x by 1
Then you call "p", result of TestNested, anoymous procedure, which:
- prints value of x
Edit: I think I know why you might think that, but even if x becomes invalid (freed?), there will still be 2 in the memory, until something overwrites it