mwr.c
text/plain
/* malloc wont release.c */
#include <unistd.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#define NUM 10000000
//#define MALLOC_SIZE 128
int main(int a, char *b[])
{
char cmd[128];
void **memtab = (void **)malloc(sizeof(void *) * NUM);
int i;
for (i = 0; i < NUM; i++) {
memtab[i] = malloc(MALLOC_SIZE);
}
for (i = 0; i < NUM; i++) {
free(memtab[i]);
}
void *first_address = memtab[0];
void *last_address = memtab[NUM - 1];
free(memtab);
printf("done\n");
snprintf(cmd, sizeof(cmd) - 1,
"grep -e ^Pss -e ^Rss /proc/%d/smaps_rollup", getpid());
system(cmd);
getchar();
malloc_trim(0);
printf("after malloc_trim:\n");
system(cmd);
getchar();
return 0;
}