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

Change variable name in adapter.observe to avoid argument capture into closure #546

Merged
merged 1 commit into from Jan 26, 2016

Conversation

blikblum
Copy link
Contributor

In the default adapter observe method the callback argument is accidentally captured into the closure. This can lead to memory leaks in situations as simple as http://codepen.io/blikblum/pen/BjYPgo

The PR also removes an redundant check in the loop

With this and mikeric/sightglass#13 most of the leaks found in the TodoMVC example ( tastejs/todomvc#1295 ) are resolved.

Some leaks still remains, which i'm looking at

@mikeric @Leeds-eBooks

@blikblum
Copy link
Contributor Author

After some investigation, i found that the two remaining detached DOM nodes in TodoMVC example does not increase over the time and is removed as soon as the view get's out of scope. It is a implementation detail from each binder and does no harm.

@benadamstyles
Copy link
Collaborator

Merging this is beyond my understanding of coffeescript, hopefully someone else can come in on this.

@blikblum
Copy link
Contributor Author

OK. An strategy is to look at the diff between compiled code before and after, but i'll understand if you still not feels confident in merging.

@@ -77,7 +77,7 @@ Rivets.public.adapters['.'] =
callbacks = map.callbacks

if callbacks[keypath]
callback() for callback in callbacks[keypath].slice() when callback in callbacks[keypath]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blikblum I understand this now. Why do you think the original author was cloning the array and checking with when? Is there a reason you haven't followed this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was an oversight or remaining of a refactoring

We already know that the callback is in the array, since we just looped over it. There's no need to check again if is in the array. Looking at the JS generated code helps to understand.

@benadamstyles benadamstyles merged commit e03550b into mikeric:master Jan 26, 2016
@blikblum
Copy link
Contributor Author

Many thanks.
We need to contact @mikeric to look into sightglass issue so we can ship a release and shift focus to es6 branch

@benadamstyles
Copy link
Collaborator

Yep, I've tried unsuccessfully to tweet him, you could email him?

@blikblum blikblum deleted the fix-mem-leaks branch January 26, 2016 21:26
@blikblum
Copy link
Contributor Author

I dont have his contact

@benadamstyles
Copy link
Collaborator

His Gmail is here https://github.com/mikeric

@blikblum
Copy link
Contributor Author

I sent him a message. Lets wait

jccazeaux pushed a commit to jccazeaux/rivets that referenced this pull request Feb 8, 2016
benadamstyles added a commit that referenced this pull request Feb 9, 2016
blikblum added a commit to blikblum/tinybind that referenced this pull request Aug 3, 2016
Don't use view.els.forEach to avoid exception when jquery is used
Report PR mikeric#546 on ES6 branch
jccazeaux pushed a commit to jccazeaux/rivets that referenced this pull request Aug 6, 2016
blikblum added a commit to blikblum/tinybind that referenced this pull request Aug 6, 2016
jccazeaux pushed a commit to jccazeaux/rivets that referenced this pull request Aug 7, 2016
benadamstyles added a commit that referenced this pull request Aug 7, 2016
Fix callback calls. See #650. Regression since #546
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.

None yet

2 participants