Hello everybody, I have a problem in GSList memory allocation.
Here is my source code:
Code:
#include <stdio.h>
#include <glib.h>
void display_list(GSList *list)
{
GSList *iterator = NULL;
printf("print the data:\n");
//print the list data
for (iterator = list; iterator; iterator = iterator->next) {
printf("%s ", (char*)iterator->data);
}
printf("\n");
}
int main(int argc, char *argv[])
{
GSList *list = NULL;
//set the GMemVTable to the default table.
g_mem_set_vtable(glib_mem_profiler_table);
//call g_mem_profile() when the application exits
g_atexit(g_mem_profile);
printf("Creat single list:\n");
//add data to list
list = g_slist_append(list, "first");
list = g_slist_append(list, "second");
list = g_slist_append(list, "third");
//print the list data
display_list(list);
//Free the list
g_slist_free(list);
return 0;
}
And here is execute result:
Quote:
Creat single list:
first second third
GLib Memory statistics (successful operations):
blocks of | allocated | freed | allocated | freed | n_bytes
n_bytes | n_times by | n_times by | n_times by | n_times by | remaining | malloc() | free() | realloc() | realloc() |
===========|============|============|============|============|===========
508 | 3 | 0 | 0 | 0 | +1524
2040 | 1 | 0 | 0 | 0 | +2040
GLib Memory statistics (failing operations):
--- none ---
Total bytes: allocated=3564, zero-initialized=3564 (100.00%), freed=0 (0.00%), remaining=3564
How to free to 3564 bytes (508*3+2040) memory space?
Please you help me.
Thank you very much!!