Jump to content

Struggling with GC in big project


Recommended Posts

We are working in a pretty big project. around 10 different games all playable in the same pixi container (not at the same time though). I have a few questions regarding garbage collection:

When trying to minimise the footprint of each game is it right to keep an eye on PIXI.utis.TextureCache and BaseTextureCache? Will this give me a full list of textures in memory?

I have noticed that just using the loader to load assets automatically adds the Textures to the TextureCache - does that sound right?

I can also see that calling destroy(true) on an AnimatedSprite only seems to remove one of the textures from its TextureArray - does that seem correct?

Looking forward to learning more...

Link to comment
Share on other sites

Most of textures are also loaded in gpu, and unloaded if not used for a minute.
"renderer.textureManager._managedTextures" "renderer.textureGC"

That stuff cannot be unloaded automatically by JS gc, that's why pixi manages it.

TextureCache/BaseTextureCache is important only for "fromImage" methods, you can clear it and nothing will happen ;)

Yeah, AnimatedSprite destroy works wrong.

In theory, if you manually clear cache from stuff you loaded - everything will be fine unless you have GENERATED textures. Any "fromCanvas", or manual creation of custom Text elements (pixi text does not appear in cache) - this is the case when you need to call destroy on textures.

Its difficult to explain pixi garbage collection strategy in one post, it has to be a big article, so most of the time i just ask people to read source-code and imagine how it works, OR just describe how your particular case works.

Link to comment
Share on other sites

A quick question:

In a small test i am doing going in and out of a game and then back in (loading the assets each time going in and destroying everything i create when going out - including resetting the loader) i get the following console warnings when going in the second time (loading the files the second time):

"BaseTexture added to the cache with an id [images/applegame/gameover-won.png] that already had an entry"

"Texture added to the cache with an id [images/applegame/gameover-won.png] that already had an entry"

This element has not been used (only loaded). How am i supposed to reference it to destroy it?


Link to comment
Share on other sites

if I need to do something like this typically i'll fetch the manifest for the assets required for the minigame,  load these assets through our asset manager,  and then on leaving the game scene I will have kept this manifest (list of files I loaded) in memory, which I can then use to destroy and unload textures.

regarding the duplicate keys, just delete them

for (const key in keys) {
    if (keys.hasOwnProperty(key)) {
        delete PIXI.utils.TextureCache[key];


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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