dimanche 25 avril 2021

Do you ALWAYS have to deallocate a dynamic variable?

This might be more of a "good practice" question, and might be somewhat unnecessary, but I think it would be nice to understand this aspect of dynamic allocation.

As far as I understand, if you don't free (deallocate) dynamically allocated variables manually, they will only be freed when your program ends. (I have read about that here)

So if I know that I will definitely need the variables, that I have created on the heap, for the whole duration of my program, isn't it okay to never delete them manually and just let the program free them when it ends?

Or is manually controlling the allocation and deallocation of dynamic variables simply a good practice?

Aucun commentaire:

Enregistrer un commentaire