# LIST how to delete an Item

**URL:** <https://forum.sierrawireless.com/t/list-how-to-delete-an-item/3767>\
**Category:** Open AT\
**Created:** [October 21, 2009, 7:07pm UTC](https://forum.sierrawireless.com/t/list-how-to-delete-an-item/3767 "2009-10-21T19:07:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dario72](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@dario72](https://forum.sierrawireless.com/u/dario72)\
**Post date:** [October 21, 2009, 7:07pm UTC](https://forum.sierrawireless.com/t/list-how-to-delete-an-item/3767/1 "2009-10-21T19:07:59Z")

</div>

Hi to all…

I’ve a big problem … I can create a list, I can add Item … but It crash if I try to delete an Item …

Can Anyone hel me 🙂

Thanks  
Dario72

I’ve declared

static wm\_lst\_t database;  
static s16 indice;

in then main  
database = wm\_lstCreate (WM\_LIST\_NONE, NULL);

and I fill then list  
indice = wm\_lstAddItem ( database, p\_data );

in other section I try to Delete with

n= wm\_lstDeleteItem ( database, indice );

---

<div class="post-metadata">

**Author:** ![davidc](https://avatars.discourse-cdn.com/v4/letter/d/a183cd/32.png) [@davidc](https://forum.sierrawireless.com/u/davidc)\
**Post date:** [October 21, 2009, 11:27pm UTC](https://forum.sierrawireless.com/t/list-how-to-delete-an-item/3767/2 "2009-10-21T23:27:09Z")

</div>

Hiya,

How is your p\_data defined?

The way the list is defined in your example, you are using the default clean up operation (which pretty much maps to adl\_memFree()) to clean up when the list item is deleted.

If your p\_data is a structure with pointers in it, then you will have to write your own clean up function to release the pointer memory before releasing the list element memory.

Also, make sure you aren’t adding automatic (i.e. local) variable to the list, as these will have gone out of scope once the function has returned and you will get an ARM exception when you try to delete them from the list.

An Example:

```auto
static wm_lst_t database;

adl_main()
{
    database = wm_lstCreate (WM_LIST_NONE, NULL);
}

void listInsert()
{
    s32 value;
    s32 *p_value;
    s32 index;

 // this is wrong, and will cause an exception when you try to access/delete the list item
    index = wm_lstAddItem(database, &value); 

// this works, as memory is allocated off the heap and remains accessable everywhere in your app
    p_value = adl_memGet(sizeof(s32));
    index = wm_lstAddItem(database, p_value); 
}
```

Hope this helps.

ciao, Dave
