fix memory leaks due to retained tagify, sortable or tooltipster instances #17483
+582
−185
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes memory leaks in character/npc/hazard/party/kingdom/item sheets and various other places.
Any application currently using
Sortable
,tooltipster
orTagify
is currently leaking memory (some references + the entire detached application dom tree) because these utilities register global event handlers or other global references that survive the application elements being detached from the DOM.The solution to this to use the respective
destroy
methods these libraries provide. Either.destroy()
on theSortable
orTagify
instances or$(element).tooltipster('destroy')
for tooltipster.This is done by keeping references to the active instances and destroying and nulling them when the application is closed, new event handlers are registered or rule element forms are not used anymore.
The memory profiles in the coming examples were done the following way:
Ideal results are: Three spikes in the allocation that reset to a flat line of exactly the same height as before the spike.
These are the results:
NPC Sheet
before PR
after PR
Character Sheet
before PR
after PR
Hazard Sheet
_Note: Hazard has to be in "unlocked" mode for tagify to be instantianted and triggere the memory leak_before PR
after PR
Kingdom Sheet
_Note: I was unable to test this one as I don't have access to the Kingmaker Premium Module._before PR
N/A
after PR
N/A
Party Sheet
before PR
after PR
IWR Editor
before PR
after PR
Compendium Browser
_Note: This requires the compendiom browser to be opened with a tab that has tagify instances. The Equipment tab for example._before PR
after PR
Pick a Thing Prompt
_Note: TODO describe which thing was picked_before PR
after PR
Encounter Tracker
_Note: This occured whenever the listeners were activated again. For testing, the encounter turn was advanced by one step._before PR
after PR
Note for Rule Elements: This was tested by creating the rule element for a standalone item, then deleting the rule element again without closing the item sheet. Even closing the item sheet however, memory was not freed.
Rule Element Forms: Actor Traits
_Note: TODO - how to test?_before PR
after PR
Rule Element Forms: Aura
before PR
after PR
Rule Element Forms: Fast Healing
_Note: Type has to be set to "regeneration" for memory leak to trigger_before PR
after PR
Rule Element Forms: Roll Note
before PR
after PR
Campaign Feature
before PR
after PR
Deity Sheet
before PR
after PR
Feat Sheet
before PR
after PR
Spell Sheet
before PR
*after PR
Scene Config Sheet
before PR
after PR
Homebrew Language Settings sheet
before PR
after PR
Skill Check Prompt Macro
before PR
after PR