- 论坛徽章:
- 0
|
在SCO UNIX下,小弟用C语言编写的程序malloc内存使用完后,用free释放,但是系统可用内存并不增加。如原来系统可用内存为100兆,malloc内存后可用内存还剩下50兆,使用完用free释放,但是系统可用内存并未增加还是50兆(按理应该是100兆);可是程序完全退出后内存完全释放。请达人们指点迷经。万分感谢!
程序例子:
#include <stdio.h>
#include <string.h>
int main(void)
{
char *str;
/* allocate memory for string */
if ((str = malloc(102400)) == NULL)
{
printf("Not enough memory to allocate buffer\n");
exit(1); /* terminate program if out of memory */
}
strcpy(str, "Hello"); /* copy "Hello" into string */
printf("String is %s\n", str); /* display string */
sleep(10);
free(str); /* free memory */
printf("End!\n");
sleep(10);
printf("Exit!\n");
return 0;
} |
|