Quantcast
Channel: Pixi.js Latest Topics
Viewing all articles
Browse latest Browse all 3978

Redrawing BitmapText every frame causes memory leak - Pixijs v5

$
0
0

Hi, I'm using PIXI.js v5.3.12 for a project and the project structures requires a call to "new BitmapText('some text', {fontName: 'my_font_name'})" every frame. Unfortunately this causes a memory leak because an 'on update' event listener is created every frame and is not GC'ed. 
Here is the stack trace of where I believe the allocation that is not freed occurs:

EE (pixi.js:1029)
addListener (pixi.js:1050)
on (pixi.js:1217)
Texture (pixi.js:15131)
BitmapText.updateText (pixi.js:36495)
BitmapText.validate (pixi.js:36637)
BitmapText.updateTransform (pixi.js:36618)
Container.updateTransform (pixi.js:8168)
Container.updateTransform (pixi.js:8168)
Renderer.render (pixi.js:22057)

Here is a compact example that reproduces the memory leak and mirrors what I am trying to do.

let container;
let loader = PIXI.Loader.shared;
loader.add("_30_font.fnt")

loader.load(() =>{

  container = new PIXI.Container();
  
  app.ticker.add(function(delta) {
    container.removeChildren();
    let bitmapText = new PIXI.BitmapText(new Date().toString(), { fontName: "_30_font"});
    bitmapText.x = 11
    bitmapText.y = 20
    container.addChild (bitmapText)
  });
    
  app.stage.addChild(container);
})

And a screenshot of a sequence of snapshots of the memory heap.

image.png.277df67dbf005140b46c4c441406ba33.png

 

I know instantiating a BitmapText every frame isn't probably the way to go but I also don't think it should cause a memory leak like this. Is it intended behaviour or just a bug?


Viewing all articles
Browse latest Browse all 3978

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>