On Wednesday, 3 January 2018 at 22:22:06 UTC, tipdbmp wrote:
x doesn't seem to be a dangling pointer, how come?
What is your definition of a dangling pointer?
In the shown example we have a reference to a piece of memory
containing 'x', so this memory is not freed, it's used by the
program. So when you access it via the pointer you get that 'x'
value, everything's ok.
The comment also shows misunderstanding: when you allocate a new
array you don't reuse the old memory, especially when it's still
used, as it is here. This is how all GC'ed languages work: as
long as you have live references to data, it's not freed and not
reused. This makes all those references valid and not "dangling".