{"action":"opened","issue":{"url":"https://api.github.com/repos/biancadanforth/tracking-protection-shield-study/issues/92","repository_url":"https://api.github.com/repos/biancadanforth/tracking-protection-shield-study","labels_url":"https://api.github.com/repos/biancadanforth/tracking-protection-shield-study/issues/92/labels{/name}","comments_url":"https://api.github.com/repos/biancadanforth/tracking-protection-shield-study/issues/92/comments","events_url":"https://api.github.com/repos/biancadanforth/tracking-protection-shield-study/issues/92/events","html_url":"https://github.com/biancadanforth/tracking-protection-shield-study/issues/92","id":296966687,"number":92,"title":"Record fixes to memory leaks for posterity","user":{"login":"biancadanforth","id":17437436,"avatar_url":"https://avatars3.githubusercontent.com/u/17437436?v=4","gravatar_id":"","url":"https://api.github.com/users/biancadanforth","html_url":"https://github.com/biancadanforth","followers_url":"https://api.github.com/users/biancadanforth/followers","following_url":"https://api.github.com/users/biancadanforth/following{/other_user}","gists_url":"https://api.github.com/users/biancadanforth/gists{/gist_id}","starred_url":"https://api.github.com/users/biancadanforth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/biancadanforth/subscriptions","organizations_url":"https://api.github.com/users/biancadanforth/orgs","repos_url":"https://api.github.com/users/biancadanforth/repos","events_url":"https://api.github.com/users/biancadanforth/events{/privacy}","received_events_url":"https://api.github.com/users/biancadanforth/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-14T03:46:21Z","updated_at":"2018-02-14T03:46:21Z","closed_at":null,"author_association":"OWNER","body":"Referencing #88 solutions\r\n\r\n### Things I've found that cause leaks:\r\n* Using strong references for window objects or their descendants\r\n  - Consider using `WeakMap` instead of `Map` for example\r\n  - Consider using `objRef = Components.utils.getWeakReference(obj)` instead of `objRef = obj`.\r\n* Ensure not only that all add/remove listeners are balanced, but that they point to the exact same reference(s) for `add` as they do for `remove`.\r\n  - Ex: Use of `bind()` and anonymous arrow functions both create a new reference for a listener.\r\n```javascript\r\nconst listenerRef = listener.bind(this);\r\n// objRef should also be the exact same reference for add and remove\r\nobjRef.addEventListener(listenerRef);\r\nobjRef.removeEventListener(listenerRef);\r\n```\r\n* Handle the case when a listener fires just before or just as the addon is shutting down.\r\n  - Consider having a state variable for `isShuttingDown` that is checked for an early return, so you prevent the possibility creating a reference that has already been cleaned up.\r\n* On shutdown, remove any remaining references to window objects or their descendants by explicitly setting them to `null` or deleting them altogether.\r\n\r\n### Resources and general notes\r\n\r\n**Resources**\r\nHere's a great MDN page on [common causes for memory leaks in extensions](https://developer.mozilla.org/en-US/docs/Extensions/Common_causes_of_memory_leaks_in_extensions).\r\n\r\nHere's a blog article I was referred to about [what to take care of during clean up in a Bootstrap extension](http://maglione-k.users.sourceforge.net/bootstrapped.xhtml).\r\n\r\n**Notes**\r\nYou must use a \"debug\" build of Firefox to test locally for memory leaks.\r\n#91 provides a helper script to test locally"}}
{"actor":{"display_login":"biancadanforth"}}