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

Suggestion - Using WeakMap() for EventCache #383

Closed
cyfung1031 opened this issue Jul 20, 2021 · 1 comment
Closed

Suggestion - Using WeakMap() for EventCache #383

cyfung1031 opened this issue Jul 20, 2021 · 1 comment

Comments

@cyfung1031
Copy link

cyfung1031 commented Jul 20, 2021

In the lastest release,

var eventsNamespace = '___ce',
...
function getEventsCache(ele) {
  return ele[eventsNamespace] = ele[eventsNamespace] || {};
}

This was the old way to bind the data to DOM. Two problems would be created ...

  1. coding is possible to get crashed if other part of the script used eventsNamespace too.
  2. possible memory leak - GC for the eventsCache

According to caniuse, >95% browsers can use WeakMap(). (all modern browsers released after 2015)
It is worth to use WeakMap() to avoid problems.

var eventsCaches = new WeakMap(),
...
function getEventsCache(ele) {
  return eventsCaches.get(ele) || (eventsCaches.set(ele, ele={}), ele);
}
@fabiospampinato
Copy link
Owner

Good idea, we should switch to that eventually.

cyfung1031 added a commit to cyfung1031/jquery-cash that referenced this issue May 3, 2023
As per fabiospampinato#383.

Chrome 36+, Edge 12+, Safari 8+, Firefox 6+, Opera 23+, IE 11+
[caniuse - WeakMap](https://caniuse.com/?search=WeakMap())

Besides, `"lib": ["ES2015.Collection"]` is added to `tsconfig.json` (`Map`, `Set`, `WeakMap`, `WeakSet` are added to TypeScript)
@cyfung1031 cyfung1031 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants