Memory Management - Clean Sound From Memory
BlitzMax Forums/BlitzMax Beginners Area/Memory Management - Clean Sound From Memory
| ||
Hi, i'm trying to understand how to clean a sound file from the memory when the file is no longer needed, Exemple : Graphics 1,1,0 FlushMem() Print "Starting "+MemAlloced() WaitKey sndSfx = LoadSound("sfx\bip.ogg",True) chan = PlaySound(sndSfx) FlushMem() Print "Playing Sound File "+MemAlloced() WaitKey StopChannel chan Release sndSfx Release sound Release chan FlushMem() Print "Stop & Clean "+MemAlloced() WaitKey You can get the bip here : [url]http://mcfox666.free.fr/sfx/bip.ogg[/url] The code gave me : Starting 85040 Playing Sound File 87712 Stop & Clean 87640 As you can see, after the "stop and clean" the sound file seams to be still here. How can I realy release it from mem ? Thanks McFox |
| ||
You have... From what I can gather, when the garbage collector frees memory it doesn't necessarily release it back to the system immediately but, for speed reasons, maintains a pool that can be reallocated when needed. This pool is released upon exit. |
| ||
Squatting: What you are talking off is only affecting memusage() not memalloced() |
| ||
It's quite possible that I'm being a knob and I've got this wrong, but this is how I see it... memusage() returns the total memory the app has allocated and de-allocated while it's been running. memalloced() shows memory allocated to the app at that time. The memory pool described above must still be allocated by blitz, otherwise what's the point? Have I got it wrong again dad? |
| ||
The memory pool described above must still be allocated by blitz, otherwise what's the point?" Yeah, there are no other reason... But Imagine a game where there are 1 music per map. If you play the game a long time, you'll have a memory leak (so you'll crash). The sound here is just a little file but immagine with a 3 Mo / music file... |
| ||
So... Anyone know how to remove the sound from mem ? |
| ||
Looks to me like an error. In maximum there should remain 4 bytes in RAM after freeing it. Did you try to program in OO style instead of procedural? |
| ||
I think you've misunderstood what I meant. I wasn't suggesting that BMax continued to hoard memory until it ran out. I was merely offering an explanation as to why the sound appeared not to be freed straight away. When you release the sound handle, the memory it used is handed over to the garbage collector to be deallocated and that may not happen immediately. AFAIC it's not a memory leak as the GC is in control. Dreamora is right though, you should really be using objects rather than integer handles... snd:TSound = Loadsound("sound.ogg") ...ETC... |
| ||
I'm looking into this - 1. the sample memory the audio mixer uses is allocated in C++ so I don't think will show up in MemAlloced / MemUsage reports 2. stopchannel is not immediate and can take up to 20ms to take effect 3. it's possibly a bug in my ogg loader code, you may want to test with .wav to see if you get the same results. |
| ||
LOL...Alright, I'm a knob then...;o) |
| ||
1. the sample memory the audio mixer uses is allocated in C++ so I don't think will show up in MemAlloced / MemUsage reports I think you're right, because the mem usage that WinXP show is different. 3. it's possibly a bug in my ogg loader code, you may want to test with .wav to see if you get the same results. leme test... I'll post after |
| ||
Ok... look at this code :Graphics 1,1,0 Type TMusic Global ChnBgm:TChannel Field Sound:TSound Method PlayMusic() ChnBgm = PlaySound(Sound) End Method Method StopAndClean() StopChannel(ChnBgm) ChnBgm = Null Sound = Null FlushMem End Method Function Create:TMusic(path$) Local snd:TMusic = New TMusic snd.Sound:TSound = LoadSound(path$,True) Return snd End Function End Type Print "1" FlushMem() Print MemAlloced() WaitKey Local bgm1:TMusic bgm1 = TMusic.Create("./bgm/test.wav") FlushMem() Print MemAlloced() WaitKey bgm1.PlayMusic() FlushMem() Print MemAlloced() WaitKey bgm1.StopAndClean() bgm1 = Null FlushMem() Print MemAlloced() WaitKey Print "2" FlushMem() Print MemAlloced() WaitKey Local bgm2:TMusic bgm2 = TMusic.Create("./bgm/test.wav") FlushMem() Print MemAlloced() WaitKey bgm2.PlayMusic() FlushMem() Print MemAlloced() WaitKey bgm2.StopAndClean() bgm2 = Null FlushMem() Print MemAlloced() WaitKey This code gave me (with my file) : 1 85022 87646 87658 87622 2 87622 87646 87658 87622 These are the value I can read with WinXP process viewer (ctrl + alt + supr) : 1 10 652 KB 15 972 KB 15 972 KB 15 972 KB 2 15 972 KB 20 868 KB 20 868 KB 20 868 KB Well... I call this a memory leak lol |
| ||
What about this... I get... Entry -> Allocated : 4398 - Used : 6592 Start -> Allocated : 96624 - Used : 113132 Load -> Allocated : 24456013 - Used : 24475756 Free -> Allocated : 99208 - Used : 119788 Start -> Allocated : 99184 - Used : 119788 Load -> Allocated : 24456013 - Used : 24475756 Free -> Allocated : 99208 - Used : 119788 Start -> Allocated : 99184 - Used : 119788 Load -> Allocated : 24456013 - Used : 24475756 Free -> Allocated : 99208 - Used : 119788 Start -> Allocated : 99184 - Used : 119788 Load -> Allocated : 24456013 - Used : 24475756 Free -> Allocated : 99208 - Used : 119788 Start -> Allocated : 99184 - Used : 119788 Load -> Allocated : 24456013 - Used : 24475756 Free -> Allocated : 99208 - Used : 119788 Start -> Allocated : 99184 - Used : 119788 Load -> Allocated : 24456013 - Used : 24475756 Free -> Allocated : 99208 - Used : 119788 Start -> Allocated : 99184 - Used : 119788 Load -> Allocated : 24456013 - Used : 24475756 Free -> Allocated : 99208 - Used : 119788 Exit -> Allocated : 99498 - Used : 119788 |
| ||
Look in WinXP proces... the mem is growting and growing every time you load the sound file |
| ||
I don't understand... Remove the Repeat char = GetChar() Until char Or (ChannelPlaying(chn) = 0) and look at windows xp process view... When the memory come around 550 MB used (that's a lot...) The memory begin to going down @ around 60-100 MB... ...What would happen on a low Ram computer... |
| ||
Oh yeah...It's leaking like a leaky thing. I wish you'd mentioned that in your first post. ;o) |
| ||
I wish you'd mentioned that in your first post. ;o) To be honnest, I didn't look at Process view when I first post, I just noticed there's a real leak after. Hope It'll be fix on next update... I can't work with sound files if there is a mem leak. (I'm not crazy lol) |
| ||
Any update on this issue? I have two projects that are depending on the ability to load/change sound files. One is a game and the other is a Jukebox program that will definately need this fixed. If there are any work arounds I would also be interested in any idea. Thanks |
| ||
This was fixed in the 1.10 update. |
| ||
Thanks TwoEyedPete. That's what I needed. I thought I had installed that update, but apparently I hadn't. Thanks again for your help. |