Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it acceptable not to deallocate memory

I'm working on a project that is supposed to be used from the command line with the following syntax:

program-name input-file

The program is supposed to process the input, compute some stuff and spit out results on stdout.

My language of choice is C++ for several reasons I'm not willing to debate. The computation phase will be highly symbolic (think compiler) and will use pretty complex dynamically allocated data structures. In particular, it's not amenable to RAII style programming.

I'm wondering if it is acceptable to forget about freeing memory, given that I expect the entire computation to consume less than the available memory and that the OS is free to reclaim all the memory in one step after the program finishes (assume program terminates in seconds). What are your feeling about this?

As a backup plan, if ever my project will require to run as a server or interactively, I figured that I can always refit a garbage collector into the source code. Does anyone have experience using garbage collectors for C++? Do they work well?

like image 235
user51568 Avatar asked Jan 30 '09 17:01

user51568


1 Answers

It shouldn't cause any problems in the specific situation described the question.

However, it's not exactly normal. Static analysis tools will complain about it. Most importantly, it builds bad habits.

like image 89
Joel Coehoorn Avatar answered Oct 11 '22 13:10

Joel Coehoorn