StopChannel frees the channel?
BlitzMax Forums/BlitzMax Programming/StopChannel frees the channel?
| ||
Hello. Been having all sorts of aggravation with sound for a few days now. I just found a few old threads that say StopChannel frees the allocated sound channel as well as stopping the sound. This confusion seems to be the cause of the problem. Thing is, I don't want the channel to be freed! I'm allocating them manually to make it easier to keep track of how many sound channels I'm using. What's the best way to stop a sound (a looped sound in my case) without freeing the channel as well? [edit] Just noticed that after a channel has been manually stopped (and consequently freed), the value remains non-null therefore garbage collection doesn't pick it up. That can't be right, can it?? |
| ||
Why shouldn't that be right? Even if collected, your reference doesn't magically change its value. That indeed would be extremely wrong. To see if it is still there, try to access it. If you don't free a channel, you can't actually have a different sound running instead, as it needs to be "done". The sound file is still present thought, so if you want to run the same sound at a later date, just use it again. (with OGG you can't use the alloced channel anyway on playsound as it gives you a memory leak unless that changed within the last 3 sync mods or the like) |
| ||
Can you Pausechannel and then play another sound using that channel? |
| ||
Gfk: I went through *exactly* the same thing a while ago and Mark or Skidracer said they wouldn't change it as it may have affected existing users's code. Dreamora is also right about the ogg memory leak. I was using PauseChannel to stop music then playing another ogg on the same channel and because I hadn't used stop channle the ogg remained in memory resulting in a huge memory leak. I posted this a little while ago. So in the end I do actually use stop channel and then just make a new channel for the next music. |
| ||
If you AllocChannel, you should FreeChannel. If not, don't - ie: if you use PlaySound to automatically allocate a channel, it will automatically be freed. |
| ||
good tip thanks. |
| ||
Mark: There is no FreeChannel command. Did you mean StopChannel? So setting a channel to Null that you've made with AllocChannel isn't an effective way of freeing it? This is quite important as I've only been nulling channels when killing a screen off. This could be a memory leak I guess...? Thanks for any answers. |
| ||
Mark: There is no FreeChannel command. Did you mean StopChannel? Been thinking exactly the same all day! |
| ||
OK some interesting test code:Strict GCCollect() Print GCMemAlloced() + " before" Local ch:TChannel = AllocChannel() Print GCMemAlloced() + " created" ch = Null GCCollect() Print GCMemAlloced() + " nulled And GCCollected" ch = AllocChannel() Print GCMemAlloced() + " created another" StopChannel(ch) GCCollect() Print GCMemAlloced() + " stopped and GCCollected" ch = Null GCCollect() Print GCMemAlloced() + " nulled and GCCollected" gives: 17290 before 17360 created 17290 nulled And GCCollected 17392 created another 17302 stopped and GCCollected 17290 nulled and GCCollected So nulling does seem to free up the memory in Blitz anyway. Stopping doesn't free it, you need to null it afterwards... So for safety, always stop then null. This will solve any ogg memory leaks and also free up the Channel pointer. |