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

leaking event handlers #17

Closed
achatham opened this issue Jan 14, 2014 · 2 comments
Closed

leaking event handlers #17

achatham opened this issue Jan 14, 2014 · 2 comments

Comments

@achatham
Copy link
Contributor

Canceling event handlers doesn't release the memory. Here's an example:

  Marker m = new Marker();
  for (int k = 0; k < 100000; ++k) {
      m.onClick.listen((_) => print('foo')).cancel();
  }

RAM used by the browser will increase each time the loop runs. It's not so bad in this example, but if the closure has references to other objects, they don't seem to be GC'd either.

If there's a different way I'm supposed to be canceling these, happy to try that.

@a14n
Copy link
Owner

a14n commented Jan 14, 2014

I can't reproduce it (in Dartium and with dart2js).

I have added the following code to https://github.com/a14n/dart-google-maps/blob/master/example/04-overlays/marker-simple/page.dart :

  marker.onClick.listen((_){
    for (int k = 0; k < 10000000; ++k) {
      marker.onClick.listen((_) => print('foo')).cancel();
    }
    window.alert('ok');
  });

When I click on the marker several times, the memory moves a little up and down but it doesn't look like a leak.

@achatham
Copy link
Contributor Author

Weird, I think we're both right. If the marker isn't attached to the map
and you instead do the listen/cancel in response to a DOM event, it runs
much slower and leaks memory. The solution in my real code is probably to
cancel everything before removing the markers from the map. Not sure if
this is worth fixing in the library, or even possible.

On Tue, Jan 14, 2014 at 12:37 AM, Alexandre Ardhuin <
notifications@github.com> wrote:

I can't reproduce it (in Dartium and with dart2js).

I have added the following code to
https://github.com/a14n/dart-google-maps/blob/master/example/04-overlays/marker-simple/page.dart:

marker.onClick.listen((){
for (int k = 0; k < 10000000; ++k) {
marker.onClick.listen((
) => print('foo')).cancel();
}
window.alert('ok');
});

When I click on the marker several times, the memory moves a little up and
down but it doesn't look like a leak.


Reply to this email directly or view it on GitHubhttps://github.com//issues/17#issuecomment-32246852
.

@a14n a14n closed this as completed Jan 14, 2014
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