-2

i have allocated memory dynamically with NEW and functionality in which it is implemented will be always keep on running,when i will forcefully terminate it will exit.i Want to deallocate memory also .how i can do that ?

Jasdeep Singh Arora
  • 543
  • 2
  • 11
  • 31

1 Answers1

4

If the block where you are allocating memory is executed multiple times, then you should think about using smart pointers to deallocate the memory when those objects go out of scope, without you calling delete explicitly.

If the block is executed only once and you want to deallocate memory when the program exits, that is not needed as the OS will reclaim all the memory allocated to your process, irrespective of whether the memory is explicitly deallocated within the process.

Vikdor
  • 23,934
  • 10
  • 61
  • 84