1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd">
5
>Memory does not seem to be released when I free the
6
list nodes I've allocated</TITLE
9
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
12
HREF="book1.html"><LINK
15
HREF="c876.html"><LINK
17
TITLE="How can I use the doubly linked lists?"
18
HREF="x895.html"><LINK
20
TITLE="Why use g_print, g_malloc, g_strdup and fellow glib
22
HREF="x909.html"></HEAD
33
SUMMARY="Header navigation table"
52
><<< Previous</A
66
>Next >>></A
79
>Memory does not seem to be released when I free the
80
list nodes I've allocated</A
83
>GLib tries to be "intelligent" on this special issue: it
84
assumes that you are likely to reuse the objects, so caches
85
the allocated memory. If you do not want to use this behavior,
86
you'll probably want to set up a special allocator.</P
88
>To quote Tim Janik:</P
92
>"If you have a certain portion of code that uses *lots*
93
of GLists or GNodes, and you know you'd better want to release
94
all of them after a short while, you'd want to use a
95
GAllocator. Pushing an allocator into g_list will make all
96
subsequent glist operations private to that allocator's memory
97
pool (and thus you have to take care to pop the allocator
98
again, before making any external calls): "</SPAN
107
CLASS="PROGRAMLISTING"
108
>GAllocator *allocator;
112
/* set a new allocation pool for GList nodes */
113
allocator = g_allocator_new ("list heap", 1024);
114
g_list_push_allocator (allocator);
116
/* do some list operations */
117
for (i = 0; i < 4096; i++)
118
list = g_list_prepend (list, NULL);
119
list = g_list_reverse (list);
121
/* beware to pop allocator befor calling external functions */
122
g_list_pop_allocator ();
123
gtk_label_set_text (GTK_LABEL (some_label), "some text");
125
/* and set our private glist pool again */
126
g_list_push_allocator (allocator);
128
/* do some list operations */
131
for (i = 0; i < 4096; i++)
132
list = g_list_prepend (list, NULL);
134
/* and back out (while freeing all of the list nodes in our pool) */
135
g_list_pop_allocator ();
136
g_allocator_free (allocator);</PRE
146
SUMMARY="Footer navigation table"
159
><<< Previous</A
177
>Next >>></A
185
>How can I use the doubly linked lists?</TD
199
>Why use g_print, g_malloc, g_strdup and fellow glib
b'\\ No newline at end of file'