Raicuparta Posted December 5, 2015 Share Posted December 5, 2015 I tried all of these: this.music.stop() this.game.sound.remove(this.music) this.music = null this.game.cache.removeSound('level_music') this.game.sound.removeByKey('level_music')They don't seem to do any difference. Every time I load a new music (with this.game.load.audio()), the memory usage goes up by a pretty big amount (some times more than 100MB) and it never goes back down, even after calling all of those functions. Also, it seems like loading the music isn't actually the main problem, playing it is what causes the memory usage? It's hard to tell. Link to comment Share on other sites More sharing options...
Kobaltic Posted December 5, 2015 Share Posted December 5, 2015 You have to destroy it.this.music.destroy();Here is the example for what you want.http://phaser.io/examples/v2/audio/remove-sound Link to comment Share on other sites More sharing options...
mattstyles Posted December 5, 2015 Share Posted December 5, 2015 I've no idea if there is a problem with your code but JS garbage collection (GC), which is the way memory is freed, tends to only be done when necessary. Chrome particularly will hold on to stuff for as long as it can. There might be some event listeners which are preventing that object from being freed (someone with more knowledge of Phaser will be able to help you there) but I suspect that the memory isnt being freed simply because it isnt necessary. The GC algorithms tend to change fairly regularly too so its sometimes hard to be 100% accurate on these things, but I would suspect Phaser would be tested for stuff like memory leaks as it sounds like you're doing something that is a regular use-case. Link to comment Share on other sites More sharing options...
chg Posted December 5, 2015 Share Posted December 5, 2015 I have a hunch that you also may not be looking at memory use but rather at the size of address space mapped to processes. Link to comment Share on other sites More sharing options...
Raicuparta Posted December 17, 2015 Author Share Posted December 17, 2015 You have to destroy it.this.music.destroy();Here is the example for what you want.http://phaser.io/examples/v2/audio/remove-soundNo idea why I didn't try the most obvious one in the first place, but it doesn't seem to be making any difference... I have a hunch that you also may not be looking at memory use but rather at the size of address space mapped to processes.I'm just looking at the memory usage in the Windows task manager, should I not be doing that? Not sure how to read the Chrome timeline thing, should I be looking at the "JS Heap"? Link to comment Share on other sites More sharing options...
chg Posted December 17, 2015 Share Posted December 17, 2015 I'm just looking at the memory usage in the Windows task manager, should I not be doing that? Not sure how to read the Chrome timeline thing, should I be looking at the "JS Heap"?You're most welcome to look at it, just take it with a huge grain of salt... take it with a really really huge grain of salt if you don't understand why the "memory usage" number next to the processes isn't strictly the amount of RAM they are using (I don't think this is the place to go into how operating systems work). As the number going up (in my opinion) cause for concern I suggest the next thing to do is nothing, but figuring out Chroming profiling tools is a great alternative - as I think you know the browser profiling tools that seem to be available for figuring out how JS code is running... Erm, will looking at the heap graph you mention tell you about the specific case you asked about ? Actually probably not (I don't think it would help you find a one off 'leak', much less that it would be fairly benign and possibly unfixable), but if you're worried about memory usage it's probably a better place to start looking. Link to comment Share on other sites More sharing options...
Recommended Posts