Tweening module having memory leak issues

I’ve noticed that my module which is made to be called by server scripts and then making a tween on the client has been having memory leakages. It is a script that is essential for VFX created by things like NPC’s

This is the script


You can faintly see that i disconnected, this is because the server crashed as a result of massive memory leakages.

Lag in action (Server lag can lead to high ping rate)
image
i’ve tried closing the thread associated for when the tween ends and these errors keeps popping up and making the problems even worse.
for some reason i can’t close a “normal” or “running” thread which is literally the biggest load of nonsense i’ve ever seen in my 2 and a half years of using studio, not to mention when an error like that occurs, the untracked memory spikes to like 3k, and so i added a condition to where it would only close the thread if it wasn’t normal or running because i don’t really know how to deal with it and i don’t know if the thread will actually garbage collect if i just set it to nil. this is the first time i’ve started using coroutines and i’m having trouble understanding on how i should use them and stuff.
also i can’t playtest my game in studio because it consumes too much memory on my pc and leads to crashes.

1 Like

You should try learning about maids. It’s quite complex to understand, but it will help you with garbage collection. You can watch this video to sum it all up. That channel also has other useful videos, for example, on the usage of promises.

What is a maid/promise?

In-short they exist to make garbage collection easier. You can make a new maid for your script and then give it a task to do. After you finish everything you can make it clean all tasks for you. This way you avoid memory leaks. Promises are like an extension to this. You can make a promise, but if it doesn’t finish before it is cleaned the task is cancelled. It’s something like “I promise it will eventually complete”.

Also, without seeing your code, we can’t really tell you where the memory leak is. If your code errors there is clearly something wrong going on. Also, if you are using an open-source module and it doesn’t work, you shouldn’t blame yourself; this happens to everyone. You think you just found the exact thing you needed for your game, but you open the script and you don’t understand anything; there is no documentation or comments.

Try implementing something simple at first, then scale it further. If running many tweens doesn’t work, try with a single one first. Understand how it works and try again. There are some common principles of programming, like “You aren’t gonna need it” or “Keep it simple stupid”. Following them can make coding a little better. Sometimes a complex solution is not the best solution.

“Also, without seeing your code, we can’t really tell you where the memory leak is”

i sent a link to the model of the script which has all the code
i don’t know where exactly the memory leak is coming from
And i made it myself, although it was inspired

so i looked at maid but i don’t know how i’m going to use it for my module
My module doesn’t use actual rbxscriptconnections but rather goodsignal and if i were to use docleaning, it wouldn’t be able to disconnect any of the events since that’s not how my module works and if i did work, it would break my module because lots of things such as npcs need to use this module.