From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,cea30133e185dc3,start X-Google-Attributes: gidfee84,public X-Google-Thread: 1014db,cea30133e185dc3,start X-Google-Attributes: gid1014db,public From: Asgar Ali Subject: How do you release memory back to the kernel in C Date: 1998/05/19 Message-ID: <35616C36.9167165F@citicorp.com>#1/1 X-Deja-AN: 354591596 Content-Transfer-Encoding: 7bit Mime-Version: 1.0 Reply-To: asgar.ali@citicorp.com X-Sender: "Asgar Ali" Content-Type: text/plain; charset=us-ascii Organization: Citicorp Newsgroups: comp.unix.osf.osf1,comp.lang.c 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. This creates the problem that if several such processes are running each needed a lot of memory at some time, none of them can share what the others have used. Hence you run out of memory quickly. I have a simple program below which illustrates the problem. The program allocates 10Mb, then another 10Mb, then frees the second, then frees the first. Both frees do not release the memory back to kernel, though the same process could reuse its free memory. I have tried tweeking some "__xxx" memory behaviour values but to no avail. Has anyone got any ideas? Asgar Ali Program: #include #include #define MEMSIZE 1024*1024*10 // 10M /* Defaults __noshrink = 0 __minshrink = 16384 __minshrinkfactor = 0.001000 __mingrow = 49152 __mingrowfactor = 0.100000 __madvisor = 0 __small_buff = 0 __fast_free_max = 13 __sbrk_override = 0 */ int main( int argc, char* argv[] ) { char charbuf[128]; char c; void* ptr; void* ptr2; printf("Allocating memory press enter "); scanf("%c", &c ); ptr = malloc( MEMSIZE ); printf("Allocating memory press enter "); scanf("%c", &c ); ptr2 = malloc( MEMSIZE ); printf("Press enter to free it "); scanf("%c", &c ); free(ptr2); printf("Press enter to free it "); scanf("%c", &c ); free(ptr); printf("Press enter to exit "); scanf("%c", &c ); return 0; }