delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/01/22:13:30

Message-ID: <B0000041587@datasoft.datasoft.com.br>
From: "Cristovao Braga" <cbraga AT datasoft DOT com DOT br>
To: "djgpp list" <djgpp AT delorie DOT com>
Subject: quick malloc question
Date: Sat, 1 Mar 1997 23:37:36 -0300
MIME-Version: 1.0

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?

I searched the djgpp docs and all I could find was this:

"This function allocates a chunk of memory from the heap large enough to
hold any object that is SIZE bytes in length.  This memory must be
returned to the heap with `free' (*note free::.)."

Please note that it says "must".

Then I conducted the following test: I run the program which source is
below under both Win95 and plain DOS with CWSDPMI. My computer has 32 MB of
RAM and in both cases I run it about 30 times in a row. The available
memory as reported by MEM.EXE did not shrink a single bit nor there was a
single indication of virtual memory usage like disc activity.

Any comments?

Cristovao Braga.

--- starts here ---

#include <stdlib.h>

char *p;

main ()
   {
      p = (char *) malloc (5 * 1024 * 1024);
   }

- Raw text -


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