Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak #257

Open
mnordine opened this issue Nov 26, 2016 · 7 comments
Open

Memory leak #257

mnordine opened this issue Nov 26, 2016 · 7 comments

Comments

@mnordine
Copy link
Contributor

This will leak until it crashes the browser:

import 'dart:html';
import 'dart:async' show Future;
import 'package:stagexl/stagexl.dart';

main() async
{
  final canvas = new CanvasElement(width: 800, height: 600);

  document.body.children.add(canvas);

  final stage = new Stage(canvas);

  new RenderLoop()..addStage(stage);

  while (true) (await loadResources()).dispose();
}

Future<ResourceManager> loadResources() async
{
  final resources = new ResourceManager();

  for (var i = 0; i < 5; i++)
    resources.addTextureAtlas('assets_$i', 'texture_atlases/assets_$i@1x.json');

  await resources.load();

  return resources;
}
@mnordine
Copy link
Contributor Author

Note that GPU memory is reclaimed perfectly.

@mnordine
Copy link
Contributor Author

In Chrome Dev Tools, Used JS Heap, Nodes, Listeners all continue to climb.

mem

@mnordine
Copy link
Contributor Author

My initial hunch was that an ImageElement was created in each ImageLoader, and that's hanging around. I tried adding a dispose to ImageLoader, but that didn't work:

void dispose()
{
  image?.remove();
  image?.src = '';
}

@bp74
Copy link
Owner

bp74 commented Nov 26, 2016

This is very interesting. It looks like as if the event listeners on the image element are not garbage collected. The number of Listeners is increasing over time. But both event listeners on the image element are canceled once the image is loaded. Will do some further investigations ...

@mnordine
Copy link
Contributor Author

mnordine commented Nov 26, 2016

I think this may be a Dartium bug. Memory seems to be getting reclaimed in Chrome after dart2js.

@mnordine
Copy link
Contributor Author

Although I'm still getting memory leaks in my more complex apps when loading/unloading texture atlases, even in Chrome

@bp74
Copy link
Owner

bp74 commented Nov 28, 2016

Yes i did a few repro cases and i saw it too. I concentrated on the EventListener that are not garbage collected, if the repro case is super simple it works - but once the code gets a little bit more complicated they are not collected anymore. Next step will be a JavaScript test to see if the behavior is similar, or if it an issue with dart/dart2js or the dart:html package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants