What does C++ do at the memory address of a variable to “deallocate” it?

  • A+
Category:Languages

For example .
When a function, that has a local integer variable x, ends, what does C++ do to the value stored at memory location corresponding to x?
Does it insert a random value?

 


This very much depends on the implementation.

In most cases nothing is done. You simply mark the memory as unused during deallocation, you don't actually do anything to the memory in this case.

In some very obscure cases you may find different things done. In one example, the RTOS RTEMS can be set up to write to the memory in dealocation. It might write something specific like 0xCDCDCDCD or 0xDEADBEEF. This can be helpful when debugging memory issues in these RTOS systems because it is easy to identify when you are using bad memory. But this is very rare.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: