Audio object does not release memory

Bugs will be moved here once resolved.

Post » Sat Aug 16, 2014 5:16 pm

Problem Description
Audio object does not release resources.

Attach a Capx
http://www.mediafire.com/download/dqltl5d4q2q1697/audioLeak.capx

Description of Capx
To demonstrate my point, capx contains 8 sound effects (they are actually long audio music files)

Steps to Reproduce Bug
  • 1. Run your memory monitor program such as Performance Monitor.
  • 2. run capx
  • 3. Press Q,W,E,R,T,Y,U,I to load and play 8 musics.
  • 4. Press S to stop music. Press 1,2,3 to go other layouts if you wish.
  • 5. You will see on the memory graph that loaded sounds are never released. There could be some small fluctuation of memory given the nature of Garbage Collector. Nevertheless, you will see the memory size will never drop down to where it was when it was first loaded.

Observed Result
Audio does not release memory. I have tested this in Node Webkit, Chrome and Firefox.

Here is memory consumption for Node Webkit. The graph rises up in the beginning because of the 8 music, but it never come back down.
Image

This here is for Firefox. The beginning is cut off, but the result is identical.
Image

I have tested this several times and I have also tried waiting for 30 minutes after changing layout to Layout 3. (Press 1,2,3 to change Layout in capx above) Memory did not go down, and Layout 3 is just a blank layout.

Expected Result
I think there should be a way for Audio object to release unused audio.

Imagine a game where each stage is themed. (ie. forest stage got wild animals sound, city stage got traffic sound, etc.) Currently, our project got 140 sound effects and about 20 musics. We have tried removing Audio object out entirely, and played through the whole game. The memory consumption is 300-400 MB after every layout has been visited. With Audio, the sounds are preloaded and played in each layout and when all layouts are visited, we got 800-900 MB. Many more audio are also coming on its way to this project, and we are afraid that with unloadable audio, this could exceed 2 GB or even more in the future. Not to mention that we also got other resources that require memory as well. Obviously, it is mandatory that we must be able to free those animal sounds when we are in the city stage and vice versa. If C2 can deallocate texture memory, then why not audio as well?

Since Web Audio API is also Javascript, is it possible to tell the Web Audio API that certain resources can now be released? This is so Garbage Collector can collect the no longer required audio? Can anything be done here to release these resources?

Affected Browsers
  • Chrome: YES
  • FireFox: YES
  • Node Webkit: YES

Operating System and Service Pack
Win7 64 bits Service Pack 1

Construct 2 Version ID
r173
I got a game that you multiply, breath fire with two heads and brawl foes to oblivion with your clones: http://www.newgrounds.com/portal/view/660664 (use Chrome on Windows for best performance)

My sites:
http://twinblazar.deviantart.com
http://twinblazar.newgrounds.com
https://twitter.com/twinblazar
http://www.pixiv.net/member.php?id=15072448
B
30
S
11
G
11
Posts: 411
Reputation: 8,469

Post » Tue Aug 19, 2014 1:47 pm

Closing as won't fix. The problem is you are categorising long music tracks as sound effects. Sound effects are designed to play with low latency and are thus held decompressed in memory at all times. Music tracks stream the compressed audio so have much lower memory usage.

It is not easy to deallocate sound effects, because if they are not loaded and suddenly need to be played, there is a delay while it decompresses the audio file again. For big sounds on mobile this can take literally seconds. Perhaps we could add an "unload audio" action to correspond with the "preload audio" action, but I don't see a compelling case here, because it's wrong to categorise music under the "sounds" category.
Scirra Founder
B
402
S
238
G
89
Posts: 24,632
Reputation: 196,031

Post » Tue Aug 19, 2014 2:58 pm

@Ashley, I used those music as sound effects to demonstrate my case here. I cannot add hundred of my sound effects from my game here, you see. These musics being used as sound effects here are like substitutes of hundreds of my sound effects. In my project, all musics are streamed.

I do understand the complication of unloading sounds. But all these unloadable sounds make my project shoot up to 900 MB in RAM in the end when I visited all layouts. (Removing audio object entirely and I got only 300 MB) And more sounds are coming to the project. This is a matter of unreleased memory and it becomes a concern for bigger project.

For deallocating sound, I understand regarding that suddenly loading a sound could lead to a brief pause as the program need to decompress and allocate once again. However, we could just add all the preloads and unloads on all sounds that will be played on this layout, on the start and end of layout to make audio a smoother experience. In fact, this is what people should be doing anyway.

I do understand that deallocating resources could be a pain to implement, but it is mandatory for running a project with a large number of sound effects.

And thank you for your explanation regarding Working Set on another thread. It really clears things up for me. I appreciate it.
I got a game that you multiply, breath fire with two heads and brawl foes to oblivion with your clones: http://www.newgrounds.com/portal/view/660664 (use Chrome on Windows for best performance)

My sites:
http://twinblazar.deviantart.com
http://twinblazar.newgrounds.com
https://twitter.com/twinblazar
http://www.pixiv.net/member.php?id=15072448
B
30
S
11
G
11
Posts: 411
Reputation: 8,469

Post » Tue Aug 19, 2014 3:20 pm

@keroberos - you could test this further in r177 by enabling/disabling 'Preload sounds' in project properties (it's a new feature) and comparing memory use. Do you really have ~600mb of sounds? Are you hoping to target mobile devices? How many sounds do you have exactly? Are any of the sounds very long (e.g. 30sec+)?
Scirra Founder
B
402
S
238
G
89
Posts: 24,632
Reputation: 196,031

Post » Tue Aug 19, 2014 4:50 pm

Hey, @Ashley, I just downloaded and tried r177.

Preload sounds YES on game startup:

Image

Preload sounds NO on game startup:

Image

All right. I see all 132 sounds (only 6.71 MB OGG in total) taking only 240 MB. Fair enough, I apologized for the trouble. Thank you for your assistance as always. :)
I got a game that you multiply, breath fire with two heads and brawl foes to oblivion with your clones: http://www.newgrounds.com/portal/view/660664 (use Chrome on Windows for best performance)

My sites:
http://twinblazar.deviantart.com
http://twinblazar.newgrounds.com
https://twitter.com/twinblazar
http://www.pixiv.net/member.php?id=15072448
B
30
S
11
G
11
Posts: 411
Reputation: 8,469

Post » Tue Aug 19, 2014 4:54 pm

I think that's relatively reasonable for audio use in a large game. Do you think it would be useful for us to add a feature to unload sounds still?
Scirra Founder
B
402
S
238
G
89
Posts: 24,632
Reputation: 196,031

Post » Tue Aug 19, 2014 5:33 pm

If I may butt in, I can give a great scenario where unloading sounds would be useful. In the case of my game (and maybe some other users down the road), I place my music files in the Sounds folder because, to my knowledge, only one Music track can be played at a time and streaming isn't exactly instant. Just close. For most users, this is sufficient, but I currently preload necessary music parts when entering a new section of my game and the soundtrack changes dynamically based on player location, game state, and other input. This is done by layering, sequencing, and swapping audio files on-the-fly. Streaming it all wouldn't be accurate enough--the next segment needs to be loaded into memory in advance so it can start truly in an instant. And I don't think they could overlap from the Music folder, anyways. It hasn't been an issue yet for my game, but I can see someone taking a stroll throughout the entire world in a single play session and getting everything loaded to memory and, for lower-end users, getting performance issues. For most users, unloading audio isn't necessary, but I do think it is a command that can definitely help in specialized cases.
B
103
S
38
G
19
Posts: 962
Reputation: 17,996

Post » Wed Aug 20, 2014 2:51 pm

@Ashley
Do you think it would be useful for us to add a feature to unload sounds still?


For me, anything allocatable should also be deallcatable. For my project in the end, there could be 600-700 MB of sound when all sounds are in the memory. Sure, we have like computers with 8 GB these days, which makes 600-700 MB not much of a concern. But for lower end devices with only 1 GB of RAM or less, unloading might allow bigger games another possibility to optimize for more memory if required. I recall Wii U got 2 GB of RAM; 1GB of RAM is allocated to system functions and only 1 GB is available for the game. Correct me if I am wrong, but is this 1 GB also used for storing texture memory as well?

So for bigger games with a wide range of variety in sound effects, unloading audio is definitely necessary for devices with limited memory.

@C-7
to my knowledge, only one Music track can be played at a time

I just tried a new capx and stream 8 music at once via Preview Chrome. All music seem to play fine simultaneously.

For most users, this is sufficient, but I currently preload necessary music parts when entering a new section of my game and the soundtrack changes dynamically based on player location, game state, and other input.

Similar to Sid Meier's Pirates! (2004)'s town scenes, I suppose? I did have tried something like that too. Streaming in C2 is designed to stream from the beginning first. Jumping around in the audio would cause a long pause. So in that case, I loaded musics as sound effects just like you.
I got a game that you multiply, breath fire with two heads and brawl foes to oblivion with your clones: http://www.newgrounds.com/portal/view/660664 (use Chrome on Windows for best performance)

My sites:
http://twinblazar.deviantart.com
http://twinblazar.newgrounds.com
https://twitter.com/twinblazar
http://www.pixiv.net/member.php?id=15072448
B
30
S
11
G
11
Posts: 411
Reputation: 8,469

Post » Wed Aug 20, 2014 4:55 pm

I'll third this motion as I have 2 sound tracks selectable at the options screen. I think I have 24 songs for each sound track and they are the length of a stage. The sound is basically about 90% of my games' size. I think it takes up about 400-500mb of ram when it's running with just one sound track at the moment. I also don't care about the delay on my end since I am only using node webkit!
B
47
S
12
G
7
Posts: 341
Reputation: 7,953

Post » Wed Aug 20, 2014 5:48 pm

i don't understand what exactly "preload action" do ?
is it mean that it will "preload" all sounds on start of the project (first layout) and then after in other layout it will just play it ? (even they are preloaded on memory )

and if we add action "preload sound" on layout A , it will be ok for layout B ? or we need to preload sound for every layout ???
B
46
S
16
G
8
Posts: 801
Reputation: 8,349

Next

Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 0 guests