Date: Tue, 12 Oct 93 16:23:46 +0100 From: fabio AT kandinsky DOT usr DOT dsi DOT unimi DOT it (Fabio Pistolesi) To: djgpp AT sun DOT soe DOT clarkson DOT edu Subject: Re: Malloc and free > > I have made a small program which is supposed to alloc > > and free memory. The problem is that it dosen't free > > the allocated memory at all. > > > #include > > #include > > > void main () > > { > > int c; > > void *p; > > > c=0; > > while (c<800) > > { > > printf ("malloc: %d bytes \n",c*10000); > > p=malloc (c*10000); > > memset (p,0xff,c*10000); > > free (p); > > getch (); > > c+=100; > > } > > } > > > I compile the program using: gcc prog.c -Wall > > > Why is'nt the memory free'd ? > > How do you know it isn't freed? There are no calls in there to check > memory status. Note that since you allocate ever-increasing block > sizes, the smaller chunks are never available for future mallocs. You > end up with a very large free list (djgpp's malloc doesn't merge free > blocks, sadly). > > Try running your test the other way - start with big packets, then > allocate ever smaller ones. > > I noticed the same problem with 2.4.1 and if you watch at debug32 memory numbers on top of screen you can see how malloc/free change the memory. Fabio