From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1014db,cea30133e185dc3 X-Google-Attributes: gid1014db,public X-Google-Thread: fee84,cea30133e185dc3 X-Google-Attributes: gidfee84,public From: Asgar Ali Subject: Re: How do you release memory back to the kernel in C Date: 1998/05/21 Message-ID: <3563E139.E7536C13@citicorp.com>#1/1 X-Deja-AN: 355169747 X-Sender: "Asgar Ali" Content-Type: text/plain; charset=us-ascii Newsgroups: comp.unix.osf.osf1,comp.lang.c Content-Transfer-Encoding: 7bit References: <35616C36.9167165F@citicorp.com> <35620a04.2342689789@207.126.101.81> Mime-Version: 1.0 Reply-To: asgar.ali@citicorp.com To: kaz@cafe.net Organization: Citicorp Sorry, the triple free(ptr) did not work on this DEC system. Kaz Kylheku wrote: > > On Tue, 19 May 1998 12:25:42 +0100, Asgar Ali wrote: > > >In DEC Unix (3.x and 4.x) I am finding that "free" does not release > >memory back to the kernel so that it could be used by other processes. > > See Peter Seebach's Infrequently Asked Questions list: > > 6.9: I have a program which mallocs but then frees a lot of memory, but memory > usage (as reported by ps) doesn't seem to go back > down. > > You're probably not freeing the memory completely. Try replacing > > free(foo); > > with > > free(foo); > free(foo); > free(foo); > > in case the first free() frees the memory only partially. (Unix wizards > may recognize the parallel with syncing three times before rebooting.) > > Alternatively, free(foo) + 4; may free the remaining four bytes. (Before > using this, make sure realloc(foo, 0) returned 4).