delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/04/07:20:23

From: gfoot AT mc31 DOT merton DOT ox DOT ac DOT uk (George Foot)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: quick malloc question
Date: 2 Mar 1997 13:50:25 GMT
Organization: Oxford University
Lines: 23
Message-ID: <5fc0j1$92p@news.ox.ac.uk>
References: <B0000041587 AT datasoft DOT datasoft DOT com DOT br> <331950FD DOT 4F9 AT cs DOT com>
NNTP-Posting-Host: mc31.merton.ox.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019