This document only talks about manual removal of events but what about automatic clean-up of events. For example, let's say the add-in adds a OnSelectionChanged event to a table that was created programmatically but then a user manually deletes the table. Does the event automatically get removed and cleaned-up on the Excel side? My assumption is yes but then any references in the javascript would need to be removed as well to allow garbage collection on the javascript side.
Also, I would assume on each refresh events are cleaned up and not persisted across sessions, correct?
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Hi @LanceEa,
I'll forward your questions to the product team and get you a definitive answer soon.
@AlexJerabek - Let me know if you need more information or for me to also add an issue to the office-js repo.
Hi @LanceEa,
I'm still following up with the product for a concrete answer, but the general answer is the event handlers do not go away until the user closes the session (or all the users in the case of Online). If you're adding a lot of handlers, I'd advise removing them as able.
@AlexJerabek - Thanks, yeah I definitely understand removing them in the scenario where something happens programmatically and that is how my add-in works today.
Its more about the non-programmatic scenarios where a user manually deletes a table. I only have an OnSelectionChange event set on the table so when the user manually deletes it I have no way of knowing it has been removed so I cannot release the reference to the javascript handler. I'm not too concerned about the javascript side (even though that could lead to a memory leak) because most users close the tabs quite frequently and this would clean up those references. The part I'm curious about is if any event handlers will still remain on the excel side or if those are clean-up by the table being deleted.
Thanks again,
Lance
@LanceEa per your prior comment -- would you mind please cross-posting this issue to the OfficeDev/office-js repo? That's probably your most expedient path for getting the info you're seeking, since members of the product team monitor that repo (but not this docs repo).
(@AlexJerabek let's leave this issue open here to track the need to update the docs with the information the product team provides in response to Lance's issue in OfficeDev/office-js.)
Hi @LanceEa,
Here's the official response I got from the product team:
"The event handlers are automatically cleaned up when the add-in is refreshed/reloaded, or when the add-in is closed. When you close the workbook, it’s also cleaned up as we do not persist the event registration information in the file. This is same for online. It’s not persisted across sessions, either.
For the below mentioned case for delete a table on which the events are registered, the event handlers are not cleaned up, but it will not be triggered. They will be cleaned up only when you refresh the add-in or close the add-in, or refresh the Excel online session."
@AlexJerabek - Thanks for getting me a detailed answer on this!
Would you like me to leave this open until something is added to the docs?
@LanceEa - My pleasure. Glad we could find you the information. Let's leave this open until I check in a doc update (just in case others have the same question). I'll close it afterwards. Thanks!
The doc updates have been merged into master and will be live soon. Closing the issue.