heap and dynamic | Sololearn: Learn to code for FREE!
+ 3

heap and dynamic

should I delete every dynamic variable I make? so I don't have memory leak? or it will be deleted when the program ends!?

28th Nov 2017, 2:48 PM
Layla A Hammoury
Layla A Hammoury - avatar
1 ответ
+ 3
Yes, you should delete dynamic variables when they are no longer needed. The operating system will take back any resource used by the program when it ends, that includes those dynamic variables. Nevertheless it's good practice to delete them, even if the program ends right after. In games for example, dynamic objects come and go and who knows how long the game keeps running, if you never delete them they will use more and more ram. Relying on the operating system to delete them is a no go.
28th Nov 2017, 3:14 PM
Dennis - avatar