I'm trying to free memory after pointers array as in a following code:
int ** t = (int**) malloc(sizeof(int*)*10000000);
printf("1\n");
getchar();
for(int i =0; i < 10000000; i++){
t[i] = (int*) malloc(sizeof(int));
*t[i] = i;
}
printf("2\n");
getchar();
for(int i =0; i < 10000000; i++){
free(t[i]);
}
printf("3\n");
getchar();
free(t);
printf("4\n");
getchar();
During the execution my system monitor shows me some strange values. When specific numbers are displayed (as in the code) i get following memory usage.
- 148K
- 390,540K
- 390,540K
- 312,676K
I'm a bit confused. Why numbers in 2 and 3 are the same? Am I doing something wrong, or system monitor is inaccurate? If it is fault of SM then why it noticed difference between 3 and 4?