# Low Level API .fsb System::createStream not closing the file handle

**URL:** <https://qa.fmod.com/t/low-level-api-fsb-system-createstream-not-closing-the-file-handle/12005>\
**Category:** FMOD Engine\
**Created:** [August 6, 2015, 9:39pm UTC](https://qa.fmod.com/t/low-level-api-fsb-system-createstream-not-closing-the-file-handle/12005 "2015-08-06T21:39:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pr0duct1ve](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@pr0duct1ve](https://qa.fmod.com/u/pr0duct1ve)\
**Post date:** [August 6, 2015, 9:39pm UTC](https://qa.fmod.com/t/low-level-api-fsb-system-createstream-not-closing-the-file-handle/12005/1 "2015-08-06T21:39:07Z")

</div>

I’m trying to figure out why my file handles to .fsb sound streams aren’t being closed. Below is a minimal example of the usage. Every time I call [PlayStream], it’s opening a file handle to the file specified, which is what I expect. HOWEVER, when I release the sound and stop the channel, the file handle still remains open. So if I were to call [PlayStream] 150 times, there would be 150 OS file handles open and I would also incur the ever-increasing memory usage associated with this as well. Main question: What is a way to properly close the .fsb file handle using the FMOD Low Level API? Do I have to close the file myself even though FMOD opens it for me?

```
FMOD_RESULT F_CALLBACK FMODMusicChannelCallback(FMOD_CHANNELCONTROL *pChanControl, 
												FMOD_CHANNELCONTROL_TYPE controlType, 
												FMOD_CHANNELCONTROL_CALLBACK_TYPE callbackType, 
												void *commandData1, void *commandData2) {
	switch(controlType) {
	case FMOD_CHANNELCONTROL_CHANNEL:
		{
			if(callbackType == FMOD_CHANNELCONTROL_CALLBACK_END) {
				FMOD::Channel *pChannel = reinterpret_cast<FMOD::Channel*>(pChanControl);
				FMOD::Sound *pSound;
				pChannel->stop();
				pChannel->getCurrentSound(&pSound);
				pSound->release();
			}
		}
	}
}

void FrameUpdate() {
	mpFMODSystem->Update();
}

void PlayStream(unsigned int subsoundID) {

	FMOD::Sound *pBaseSound, *pSubSound;
	FMOD::Channel *pChannel;

	mpFMODSystem->createStream("soundbankwithsubsounds.fsb", FMOD_LOOP_OFF|FMOD_2D, NULL, &pBaseSound);
	pBaseSound->getSubSound(subsoundID, &pSubSound);
	mpFMODSystem->playSound(pSubSound, NULL, false, &pChannel);
	pChannel->setCallback(FMODMusicChannelCallback);
}
```

---

<div class="post-metadata">

**Author:** ![pr0duct1ve](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@pr0duct1ve](https://qa.fmod.com/u/pr0duct1ve)\
**Post date:** [August 6, 2015, 10:56pm UTC](https://qa.fmod.com/t/low-level-api-fsb-system-createstream-not-closing-the-file-handle/12005/2 "2015-08-06T22:56:33Z")

</div>

Woah there stop the presses!! I figured it out.

When streaming from a bank using a subSound, you’ve got to call [release()] on the **parent** sound that was initially created from [createStream()]. If you don’t call [release()] on the **parent** , then the handle stays open since the parent FMOD::Sound isn’t released at all. You can retrieve the parent (or check if there is a parent) by using [FMOD:🔉:getSubSoundParent]. If the value retrieved is NULL, then I’m assuming you most likely have a parent already.
