Re: [gtk-list] Re: potential problems with malloc/free vs. C++ new/delete ???




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




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]