# Deleting FMOD\_CHANNEL array crashes the program.

**URL:** <https://qa.fmod.com/t/deleting-fmod-channel-array-crashes-the-program/14082>\
**Category:** FMOD Engine\
**Created:** [September 1, 2018, 8:45am UTC](https://qa.fmod.com/t/deleting-fmod-channel-array-crashes-the-program/14082 "2018-09-01T08:45:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jedah](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@Jedah](https://qa.fmod.com/u/Jedah)\
**Post date:** [September 1, 2018, 8:45am UTC](https://qa.fmod.com/t/deleting-fmod-channel-array-crashes-the-program/14082/1 "2018-09-01T08:45:17Z")

</div>

FMOD\_CHANNEL\*\* channel = static\_cast\<FMOD\_CHANNEL\*\*\>(realloc(channel, musicCount_sizeof(FMOD\_CHANNEL_)));

Every time a music is added, a memory is dynamically allocated to channel array.  
However, when I free the array like this, free(channel); the program crashes.  
How can I handle this?

---

<div class="post-metadata">

**Author:** ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)\
**Post date:** [September 3, 2018, 12:59am UTC](https://qa.fmod.com/t/deleting-fmod-channel-array-crashes-the-program/14082/2 "2018-09-03T00:59:21Z")

</div>

Hi, this doesn’t really seem to be FMOD related?  
You are dynamically allocating memory to store the channels for your music, then freeing them, but i am assuming you’re still using the original pointer in some other part of the code that is causing the crash?

FMOD returns a pointer to a channel that is already allocated inside the fmod engine yourself. I’m not sure why you need to allocate memory to store a 4 or 8 byte pointer.  
If you have multiple channels for music, you could just be storing an array of FMOD\_CHANNEL pointers in a struct.

Allocating and freeing lots of little pieces of memory leads to memory fragmentation and bad performance.
