Jump to content

Removing cache for music


fitness23
 Share

Recommended Posts

I've asked this question several times but to no luck, so trying again :)

I have the following code: 

this.game.cache.removeSound(gameData.rooms[i].musicID);

However it doesn't actually seem to remove the cache at all. Has a newer version fixed this bug at all?

I'm desperate at this point. I have a point and click adventure game with several different rooms. Each room has a different piece of music playing and if you've gone to say 5 different rooms, 5 different pieces of music are in memory and causes the game to crash on mobile.

Link to comment
Share on other sites

For me it works fine on Phaser 2.6.1:

game.cache._cache.sound.test
Object {url: "test.ogg", data: AudioBuffer, isDecoding: false, decoded: true, webAudio: true…}

game.cache.removeSound('test')
undefined

game.cache._cache.sound.test
undefined

So I see nothing wrong with the cache itself, it's more probable that you still have a reference somewhere in your code to the sound file that needs cleaning up.

Link to comment
Share on other sites

Thanks for you reply @Str1ngS :)

Ok so I upgraded to Phaser 2.6.1 which was fine.

I used the line that I was using before:

this.game.cache.removeSound(gameData.rooms[i].musicID);

and then I ran the test and it came back undefined which I expected. However the cache still seems to go up and up. It's going up by 100mb for each sound track.

I removed all the references that use that sound key using the following lines:

backgroundMusic.stop();
backgroundMusic.destroy();
backgroundMusic = null;
this.game.cache.removeSound(gameData.rooms[i].musicID);
						
console.log(this.game.cache._cache.sound.beachSceneMusic);

Is there anything else that I'm missing?

Link to comment
Share on other sites

Quote

However the cache still seems to go up and up. It's going up by 100mb for each sound track.

With cache, do you mean just the memory heap? Or Phaser's internal cache storage (cache._cache)? Also how big are those music files that they are managing to crash a mobile? The average mp3/ogg loop we use are max a couple of Mb's

Link to comment
Share on other sites

Chrome's task manager gives you a complete overview of what Chrome needs to draw the page, this is on average a lot more then just the JS memory heap (which is what we care about, and more or less have most control over). The measures stated in there are interesting, but don't really help you fix issues regarding memory consumption of your app (and probably also not the reason why it crashes on mobile.)

 

As for the memory heap, there are 2 ways in Chrome to review them.

The simpelest way is creating a snapshot, which can be done in the developer tools under Profiles. Taking a heapsnapshot gives you an accurate overview of the actual object in memory. It's also possible to diff 2 snapshots but you can read about that over here: https://developer.chrome.com/devtools/docs/heap-profiling

The second way is a bit more interesting to you, because it will show you memory allocation over time, you can use this to check how much memory is used between your states, but also when Chrome does some garbage collection on your memory. You can find this option in the developer tools under Timeline, also read more about it here: https://developers.google.com/web/tools/chrome-devtools/profile/evaluate-performance/timeline-tool

 

With these 2 options you should be more than capable of finding memory leaks in your code.

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...