Re: [gtk-list] Re: potential problems with malloc/free vs. C++ new/delete ???
- From: Dave Reed <dreed capital edu>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Re: potential problems with malloc/free vs. C++ new/delete ???
- Date: Thu, 3 Dec 1998 20:25:14 -0500
> From: Havoc Pennington <rhpennin@midway.uchicago.edu>
> On Thu, 3 Dec 1998, Dave Reed wrote:
> >
> > So do I have a memory leak then? What is the proper way around this?
> > Do I have to remember to delete all the strings myself after calling
> > the gtk_clist_clear() function. Or can I delete them after adding
> > them to the clist? I thought I tried using the same string with
> > different values each time I added them to the clist and I ended up
> > with all the entries being the same as the last one I had set the
> > string to.
> >
> > e.g,
> >
> > sprintf(str, "a");
> > // add to clist
> > sprintf(str, "b");
> > // add to clist
> >
> > and both entries would be b.
> >
>
> Should work, maybe something else was wrong. I usually end up doing this:
Yes, you're correct, it does work - here is the example I wasn't
remembering:
The g_list clearly must just keep a pointer to the data so I had to
have a separate string for each one.
char *listStr;
while (nextCatHead(heading)) {
heading->initIterator();
while (heading->next(category)) {
listStr = (char *) g_malloc(sizeof(char) * 100);
sprintf(listStr, "%s %s", category->id().c_str(),
category->name().c_str());
catItems = g_list_append(catItems, listStr);
}
}
gtk_combo_set_popdown_strings(GTK_COMBO(categoryCombo_), catItems);
Should I be freeing anything here after it gets added to the combo?
What part of the documentation should I be looking in to find the
answers to these kind of memory questions?
Thanks again - you've been a big help.
Dave
dreed@capital.edu
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]