[10669] in The GTK GIMP ToolKit mailing list archive
[gtk-list] Re: potential problems with malloc/free vs. C++ new/delete ???
daemon@ATHENA.MIT.EDU (Havoc Pennington)
Thu Dec 3 19:45:35 1998
Date: Thu, 3 Dec 1998 18:25:19 -0600 (CST)
From: Havoc Pennington <rhpennin@midway.uchicago.edu>
To: gtk-list@redhat.com
In-Reply-To: <199812032237.RAA09377@fourier.capital.edu.capital.edu>
Resent-From: gtk-list@redhat.com
Reply-To: gtk-list@redhat.com
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:
char* text[3];
text[0] = "some_string";
text[1] = get_another_string();
text[2] = get_string_2();
etc. You then stuff in the CList, and if anything needs to be freed it's
safe to do that right after the call to gtk_clist_append() (or insert).
Havoc
--
To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null