Release Memory After Audio Preload

Get help using Construct 2

Post » Thu Jun 06, 2013 5:34 am

I've noticed that while preloading audio files, memory usage tends to spike pretty high. The problem I'm having is that after all preloading is complete, the memory stays spiked. I thought construct dealt with memory on a layout-by-layout basis, but even after switching layouts the situation remains.

I've tested this in preview, html5 export, and node-webkit. What's strange is that sometimes the memory will actually dip back down after preloads completed, but it seems to only happen randomly. Even with no event changes on my end.

I should note that I'm preloading several songs but that shouldn't be much of an issue. I know it's not being executed the same way but here's an example of 12 3-minute audio files being loaded with html that only uses about 150m http://kevincennis.com/mix . When I try to load the same amount of tracks of approximately the same length, memory usage shoots up to 650m.

I don't think it's a coding thing on my end but here's the capx file anyway - minus the audio for file size http://db.tt/JuVvP8yE . If what I'm experiencing isn't a bug, is there a workaround I can use to flush the memory somehow, but keep the audio files ready for playback? Thanks for any insight.
B
8
S
2
G
1
Posts: 12
Reputation: 1,349

Post » Thu Jun 06, 2013 1:55 pm

Browsers don't provide any feature to flush audio memory, so we cannot add one. Instead, they use garbage collection. If the memory use gets too high they will release things from memory. If it can fit in memory it will probably keep it there. So it's probably nothing to worry about.
Scirra Founder
B
395
S
232
G
88
Posts: 24,371
Reputation: 193,772

Post » Thu Jun 06, 2013 2:01 pm

Is there no way to force garbage collection through a plugin though Ashley?

Ex. http://stackoverflow.com/questions/3034179/javascript-force-gc-collection-forcefully-free-object
B
6
S
1
Posts: 62
Reputation: 532

Post » Thu Jun 06, 2013 11:49 pm

Interesting, that's good to know. The problem is that I have even more files than in that example, and almost every time it tries to load, it crashes. Maybe it's using up memory so quickly that the browser can't dump it? Though, I've tried staggering loads as a test - waiting for one small-batch preload to finish and then start another - and that doesn't seem to help either.
B
8
S
2
G
1
Posts: 12
Reputation: 1,349

Post » Fri Jun 07, 2013 1:26 pm

Javascript provides no mechanism by which a garbage collection can be forced. The obvious thing to do seems to be: just don't preload anything apart from the handful of most latency-sensitive sound effects. In particular, you should not preload any music at all.Ashley2013-06-07 13:27:37
Scirra Founder
B
395
S
232
G
88
Posts: 24,371
Reputation: 193,772

Post » Fri Jun 07, 2013 8:59 pm

I hear that - wish I could. The project I'm working on is similar in idea to that mixer I linked to earlier, so basically everything is latency-sensitive. Unfortunately when I try to run it as Music and not Sound, things get pretty far out of sync. And when I just play them as Sound without preloading them first, the memory still jumps like crazy. In this scenario it also starts playing each channel when it finishing so the first track can be as far as a minute ahead of the final loading track. Still not sure what the best plan is yet but thanks for all the feedback!
B
8
S
2
G
1
Posts: 12
Reputation: 1,349


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 62 guests