Re: Free memory from list

Donald Jackson <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Create a destroy function for your structure, then use
gwlist_destroy(list, your_destroy_function); to destroy the list and
all contained data.

Thanks,
Donald

On 2/23/10, Esteban Cacavelos <[email protected]> wrote:
> Hi all,
>
>
> I'am having some troubles to free memory from a list
>
> the list item is like that:
>
> typedef struct structT
>     {
>         Octstr *string2;
>         Octstr * string1;
>         int varInt1;
>         int varInt2;
>
>     }STRUCT_T;
>
> if the list contains N items of type STRUCT_T, how i should free the memory
> allocated ?
>
> i did as follow,
>
> STRUCT_T * item;
>
>   for (i = 0  ; i < gwlist_len(my_list); i++)
>           {
>              item = gwlist_get(my_list,i);
>              octstr_destroy(item->string1);
>              octstr_destroy (item->string2);
>              gw_free(item);
>
>           }//DESTROY ALL ITEMS
>
>           for (i = 0  ; i < gwlist_len(my_list); i++)
>           {
>              gwlist_delete(my_list, 0, 1);
>           }//DESTROY ELEMENTS FROM THE LIST
>
> But, apparently it is not correct or i missing something because the memory
> usage of the applicacion grows up.
>
>
>
> Thanks,
>
>
>
> --
> Esteban L. Cacavelos de Amoriza
> Cel: 0981 220 429
>


-- 
Donald Jackson
http://www.elite-sms-software.com
http://www.ddj.co.za
http://www.thearchitech.com
donald(a)thearchitech.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.