Originally posted by: Special K
If I forget to call free() on some allocated memory within my program, will the OS automatically free up all memory the program might have allocated when I exit the program?
Originally posted by: bsobel
The core question has been answered, but I need to ask why the inquirery, this is certainly not the way to design software.
Originally posted by: Madwand1
Originally posted by: bsobel
The core question has been answered, but I need to ask why the inquirery, this is certainly not the way to design software.
Agree with that, and let me give one reason why: You're setting yourself up for memory leaks in the program. If you have a bunch of unfreed memory by design, then you'll miss any warnings about unfreed memory not by design at the end in the noise.
Originally posted by: Templeton
I've got to disagree, it depends entirely on the program. There are many situations where you simply don't care about the memory that's lying around, it's faster to just exit when the user tells you to. This is especially true when the programs been unused for awhile with lots of memory paged out, why spend time to page memory back in just to free crap that the OS will reclaim for you?
depends on the os... but yes if it's fairly new (i.e. win9x might not)
Originally posted by: Special K
Thanks for the replies. I went ahead and manually freed all of the memory myself. If I didn't, I was not able to run the program more than once without having to quit and exit again, because pointers would start walking all over each other and the program would crash.
I now have a related question. Suppose I do this (see code below):
Let's say that foo's return type is char* (pointer to char), and that the line I have is the initial declaration of tmp_ptr. Will I get into trouble by not allocating space to tmp_ptr before assigning it to the return value of foo(), or will that be handled automatically?
I've got to disagree, it depends entirely on the program. There are many situations where you simply don't care about the memory that's lying around, it's faster to just exit when the user tells you to. This is especially true when the programs been unused for awhile with lots of memory paged out, why spend time to page memory back in just to free crap that the OS will reclaim for you?
why spend time to page memory back in just to free crap that the OS will reclaim for you?