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

Prevent memory leaks in rivets adapters fix #10 #12

Closed
wants to merge 1 commit into from

Conversation

nopnop
Copy link

@nopnop nopnop commented Jun 11, 2015

Using .bind(this) on Observer#update() create a new function instance each time: thereby, adapters can’t unobserve sightglass update callback.

The solution is to keep an reference to the binded update method.

A pull request (#11) has allready been proposed by @jccazeaux, but:

  • @jccazeaux ’s PR do not work at all: var self is unproperly initialised in the constructor, not in the methods that use it. And... anyway, even with self properly initialised, using self.update remains a mistake (self.update remain a function, not an instance method)
  • Maybe its ok to use .bind() instead of var self, because browsers support is large enough (and polyfilling bind() is easy)

Fix #10 and mikeric/rivets#430

Using `.bind(this)` on `Observer#update()` create a new function
instance each time: thereby, adapters can’t unobserve sightglass 
update callback.

The solution is to keep an reference to the *binded* update method. 

A pull request (mikeric#11) has allready been proposed by @jccazeaux, but:

- @jccazeaux ’s PR do not work at all: `var self` is unproperly 
  initialised in the constructor, not in the methods that use it. 
  And... anyway, even with `self` properly initialised, using 
  `self.update` remains a mistake (self.update remain a function, not
  an instance method)
- Maybe its ok to use `.bind()` instead of `var self`, because 
  [browsers support](http://kangax.github.io/compat-table/es5/#Function.prototype.bind)
  is large enough (and polyfilling bind() is easy)
@nopnop
Copy link
Author

nopnop commented Jun 11, 2015

And here is two fiddle to illustrate the PR:

@jccazeaux
Copy link

Oh my, you're right !
I had no problem on my tests, must have missed something

@nopnop
Copy link
Author

nopnop commented Aug 13, 2015

Hi @mikeric, is there anything that prevent you to merge this ? :)

@jhnns
Copy link

jhnns commented Sep 24, 2015

👍

@jccazeaux
Copy link

This PR can be closed, #13 is the same and has been merged

@nopnop nopnop closed this Feb 10, 2016
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

Successfully merging this pull request may close these issues.

3 participants