ModuleScripts do not disconnect events when destroyed

When a ModuleScript is destroyed, the events it creates do not get disconnected, this has significant performance implications, especially when developing plugins, as plugins can be reloaded multiple times in one session, creating a memory cost every time we reload it.

Below is a repro of this happening with a plugin, if you reload and resize the baseplate, you’ll notice the prints increase for every time the plugin is reloaded.

Repro.rbxm (1.6 KB)

image

Expected behavior

When a ModuleScript is destroyed, it should disconnect any events that were created from within the ModuleScript, similar to how it does with scripts.

1 Like

Thank you for the report.

This is by design and developers heavily rely on destroyed ModuleScript threads continuing to run even after being destroyed (they even expect to get the same cached table after Destroy).

We do not plan to change this behavior at this time.