Slaus Posted December 28, 2018 Share Posted December 28, 2018 Hello. I'm drawing charts with Graphics.generateCanvasTexture() every frame. I need exactly canvas renderer due to antialiasing. The problem is browser's memory usage going from 200Mb to 1.2Gb in mere seconds. Invoking texture.destroy() doesn't help. There was a talk about canvas creation memory leak and folks seemed to handle it somehow, but I can't figure out how they did Is there any way to destroy such previously created textures or reuse them to create successive ones? Thanks in advance Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted December 28, 2018 Share Posted December 28, 2018 texture.destroy() is the only way to get rid of generated textures. Quote Link to comment Share on other sites More sharing options...
Slaus Posted December 28, 2018 Author Share Posted December 28, 2018 Thank you for your answer. So I guess it's some trouble with releasing canvas objects which spawn on Graphics.generateCanvasTexture() calls? Maybe there is a way to release all the previously created canvas objects? I was looking to https://github.com/photonstorm/phaser/blob/v2.4.3/src/pixi/utils/CanvasPool.js photonstorm was suggesting in that thread, but there is no connection with PIXI, so I guess I'll have to patch Graphics.js somehow? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted December 28, 2018 Share Posted December 28, 2018 Ok, `texture.destroy(true)` - destroys baseTexture, canvas will b freed automatically by JS garbage collector. Pool will just swap one type of problems to another type, result will be the same if you are not ready for it. Quote Link to comment Share on other sites More sharing options...
Slaus Posted December 28, 2018 Author Share Posted December 28, 2018 Done! Memory usage is very stationary at ~200Mb. Thank you very much! But I don't understand your pessimism about "just moving problem to another domain". Is there something else I need to worry about? Relying on GC in untyped imperative language is the only way to go, I think ^^ Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted December 28, 2018 Share Posted December 28, 2018 Pooled objects retain links to other objects sometimes, and sometimes you can re-use already existing object 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.