fideldonson Posted December 13, 2018 Share Posted December 13, 2018 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... Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted December 13, 2018 Share Posted December 13, 2018 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. Quote Link to comment Share on other sites More sharing options...
fideldonson Posted December 13, 2018 Author Share Posted December 13, 2018 Hi Ivan - thanks for getting back to me so quickly. I'm slowly working my way up to creating my own resource manager. I think you should add that bit about the animatedSprite to this page: https://github.com/pixijs/pixi.js/wiki/v4-Gotchas ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
fideldonson Posted December 13, 2018 Author Share Posted December 13, 2018 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? Quote Link to comment Share on other sites More sharing options...
Owlzy Posted December 14, 2018 Share Posted December 14, 2018 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]; } } Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted December 14, 2018 Share Posted December 14, 2018 I think we have to fix this thing, instead of adding it to v4-gotchas, both in v4 and v5 Quote Link to comment Share on other sites More sharing options...
adam.drake Posted June 14, 2022 Share Posted June 14, 2022 (edited) On 12/13/2018 at 1:00 PM, ivan.popelyshev said: Most of textures are also loaded in gpu, and unloaded if not used for a minute. "renderer.textureManager._managedTextures" "renderer.textureGC" Sorry for the necro but is there a way to prevent a texture from being unloaded automatically? I'm loading some effects into my game which appear semi-rarely, but will cause a very noticeable freeze when being displayed for the first time. I'm preparing the textures with pixi v5, which works fine until they're unloaded. Edited June 14, 2022 by adam.drake Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted June 16, 2022 Share Posted June 16, 2022 yes, turn off gc or somehow make it ignore particular texture. TextureGCSystem is available from outside, means you can override methods in prototype Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.