私はCを初めて使用します。malloc+無料に慣れようとしています。次のテストをコーディングしましたが、何らかの理由でメモリが完全に解放されていません(上部にはまだ約150MBのメモリが処理に割り当てられていることが示されています)。何故ですか?
#include <stdio.h>
#include <malloc.h>
typedef struct {
char *inner;
} structure;
int main()
{
int i;
structure** structureArray;
structureArray = (structure**)malloc(sizeof(structure*)*1000*10000);
for (i = 0; i < 1000*10000;i++)
{
structureArray[i] = (structure*) malloc(sizeof(structure));
structureArray[i]->inner = (char*) malloc(sizeof(char)*1000*1000*1000);
}
printf("freeing memory");
for (i = 0; i < 1000*10000;i++)
{
free(structureArray[i]->inner);
free(structureArray[i]);
}
free(structureArray);
system("sleep 100");
return 0;
}
対応するMakefile:
all: test.c
gcc -o test test.c
./test &
top -p `pidof ./test`
killall ./test