Skip to content

Y.Node._instances breaks GC#1637

Closed
jafl wants to merge 7 commits into
yui:dev-masterfrom
jafl:fix-node-gc-2
Closed

Y.Node._instances breaks GC#1637
jafl wants to merge 7 commits into
yui:dev-masterfrom
jafl:fix-node-gc-2

Conversation

@jafl

@jafl jafl commented Feb 12, 2014

Copy link
Copy Markdown
Contributor

This picks up where the old Ticket #2532270 left off.

Breaking the GC model drags us back to manual memory management. IE6 and IE7 force us to do this anyway, but YUI should not force this upon developers who choose to not target these older browsers.

Another example: If I dereference a Node instance and pass it to a 3rd party widget that operates on raw DOM elements, then even if that widget cleans up correctly, the DOM node won't get cleaned up as long as the Node instance still exists.

By storing the Y.Node reference on the DOM element instead of in Y.Node._instances, then none of this is a problem.

@jafl

jafl commented Feb 13, 2014

Copy link
Copy Markdown
Contributor Author

The failed build is due to Charts. I think that must also be in dev-master, not related to my changes.

@juandopazo

Copy link
Copy Markdown
Member

Sorry for rehasing. If the goal is to only fix this in modern browsers, can we just use a WeakMap and slowly get the new behavior as browsers implement it? It's a lot simpler than keeping a flag everywhere and it's already there in Firefox and IE11.

@jafl

jafl commented Feb 13, 2014

Copy link
Copy Markdown
Contributor Author

My understanding of WeakMap is that (1) the keys are objects and (2) only the keys are subject to garbage collection. Since the keys in Y.Node._instances are strings, WeakMap doesn't sound applicable.

@juandopazo

Copy link
Copy Markdown
Member

But the idea is to map DOM Nodes to YUI Nodes. When using the WeakMap you'd just use the DOM node as the key.

@jafl

jafl commented Feb 13, 2014

Copy link
Copy Markdown
Contributor Author

Doh. You're right. However, I'm not sure the code will be any simpler, because you'll still have to test whether or not WeakMap is available. And it looks like it may still be a while before it's available in enough browsers to be reliable. If it's only available in some browsers, it's no help, because you still have to keep doing manual memory management. My patch fixes it for everything except IE6 and IE7, which are already basically dead.

@juandopazo

Copy link
Copy Markdown
Member

I think your implementation is fine (storing the YUI node in the DOM node), but I still think we should be using a WeakMap as the correct future-proof solution.

@jafl

jafl commented Feb 13, 2014

Copy link
Copy Markdown
Contributor Author

I agree that WeakMap is the ideal long-term solution.

@jafl

jafl commented Jan 14, 2019

Copy link
Copy Markdown
Contributor Author

moved to #2014

@jafl jafl closed this Jan 14, 2019
@jafl jafl deleted the fix-node-gc-2 branch January 29, 2019 19:15
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.

2 participants