Mail Archives: djgpp/1997/03/04/07:20:23
John M. Aldrich (fighteer AT cs DOT com) wrote:
: Cristovao Braga wrote:
: >
: > I was wondering: if I allocate some memory with malloc () or an equivalent
: > function and then quit the program without calling free (), will this
: > memory be freed automatically?
: Yes. It's automatically freed by the program's exit code. There are
: some purists who say you should free it anyway - I'm ambivalent on the
: issue. :)
IMHO, if you can't free the memory at the end of the program, there's
something wrong with your code. I think it's bad practise to lose track
of the memory you've been given - if for any reason you later need to
loop the entire program, for instance, (e.g. you're writing a game, and
you now want the code to repeat after each game) you can't afford to
lose memory all the time - you'll run out.
I don't think I'm a purist, though ;)
--
George Foot <gfoot AT mc31 DOT merton DOT ox DOT ac DOT uk>
Merton College, Oxford.
- Raw text -