В моей простой программе на C (gnu linux) я получаю значение rss из proc / stat.
int GetRSS()
возвращает значение RSS из proc / stat для моего процесса.
В этом случае:
printf("A RSS=%i\n", GetRSS());
char *cStr = null;
cStr = malloc(999999);
if (cStr != NULL)
{
printf("B RSS=%i\n", GetRSS());
free(cStr);
printf("C RSS=%i\n", GetRSS());
}
Я получаю:
A RSS=980
B RSS=984
C RSS=980
Я не могу объяснить, почему C
не вернул 984
.
Если я запускаю одну и ту же процедуру дважды, я получаю:
A RSS=980
B RSS=984
C RSS=980
B RSS=984
C RSS=980
Выглядит хорошо.
Но, в данном случае:
struct _test
{
char *pChar;
}
struct _test **test_ptr;
int i = 0;
printf("D RSS=%i\n",GetRSS());
assert(test_ptr = (struct _test **)malloc( (10000) * sizeof(struct _test *)));
for (i = 0; i < 1000; i++)
{
assert(test_ptr[i] = (struct _test *)malloc(sizeof(struct _test)));
test_ptr[i]->pChar=strdup("Some garbage");
}
printf("E RSS=%i\n", GetRSS());
for (i=0; i<1000; i++)
{
free(test_ptr[i]->pChar);
free(test_ptr[i]);
}
free(test_ptr);
printf("F RSS=%i\n", GetRSS());
Я получаю:
D RSS=980
E RSS=1024
F RSS=1024
D RSS=1024
E RSS=1024
F RSS=1024
А?Почему память не освобождается здесь?