Voldemalort / token-factions

Foundry VTT Module: Token Factions
4 stars 8 forks source link

Memory Leak when Moving tokens #13

Open nathanhoobler opened 3 years ago

nathanhoobler commented 3 years ago

FoundryVTT 0.7.9 token-factions 0.2.1

Module Settings: Generate Token's Faction Color From: Use an Actor's Folder Color Frame Render Style: Beveled

There appears to be a memory leak that occurs whenever I move tokens with faction markers around the screen. Memory usage increases and performance degrades until the frame finally crashes and I have to re-load the client (at which point memory utilization is reset but the bug remains).

Voldemalort commented 3 years ago

Have you disabled all other modules? I tried to reproduce this unsuccessfully and would typically need a console error or to see it reproduceable without any other modules enabled to consider it a bug.

nathanhoobler commented 3 years ago

This happened during a play session so I didn't do an exhaustive test yet. It did disappear when I disabled the Token Factions module, but you are right -- it might be an interaction with another active module.

When I have a chance I will see if I can reproduce it in isolation (and if no what combination of modules is causing the issue).

On Wed, Dec 30, 2020 at 12:49 PM Voldemalort notifications@github.com wrote:

Have you disabled all other modules? I tried to reproduce this unsuccessfully and would typically need a console error or to see it reproduceable without any other modules enabled to consider it a bug.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Voldemalort/token-factions/issues/13#issuecomment-752704471, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEJNEMRBWNAIJVCQO7XCVLLSXNRZXANCNFSM4VOQLDUA .

erithtotl commented 3 years ago

So I've been suffering from a significant memory leak for awhile. I just recently used 'Find the Culprit', and narrowed it down to this module. It's more than just moving a token, just selecting it. I tested on my current map. Without Token Factions, clicking on an individual token might add <5K to the javascript memory (using Chrome Task window). I can click on 20 or so tokens quickly, see usage go from 50-60K javascript to 90K or so, and then eventually drop back down. This is with or without nearly 80 modules active.

If I activate token factions, that same activity spikes javascript memory to 500K! A bit less without all the other modules, but still in the 200K+ range. And clicking on the same token again adds, so its not like data is being cached, its truly orphaned.

I just experimented with selecting the same token over and over (selecting then deselecting, repeat). Without Token-factions, memory ticks up 2-5K per click, but within some seconds decreases back down to roughly the starting point (presumably garbage collected). With token factions on, it ticks up 10-20K per click, but doesn't decrease appreciably even after minutes.

I think I have figured out the problem. Instead of calling .destroy() on the PIXI container, you need to call .destroy({children:true}) which will destroy all the children of the container as well (can't do .destroy(true) as this will also destroy your global bevelGradient/bevelTexture. I just ran a quick test and it worked. Will run it with my gaming group tonight and if we make it through the evening without the memory leaks, will do a pull request.

anathemamask commented 3 years ago

Confirmed bug caused by Token Factions.

Steps for reproduction:

Voldemalort commented 3 years ago

Sorry for the long absence - life events happened that prevented me from addressing these issues. I'll be trying to reconcile all of the activity in the next couple of days. Thanks for your contributions!