To be clear, I have a client memory leak, so the character destroy behavior doesn’t really do much because according the the link it affects server memory. I could be wrong though.
I have a lot of connections that I don’t specifically disconnect but are connected to the character or instances that are children of the character. I’d assume they are disconnected when the character is respawned, but I’m not sure.
Another thing is I have a lot of tweens being created in run service loops. Does this cause memory leaks?
Another thing is that I have a camera shaker Oop object that is created but never “destroyed” when the character dies. Do I have to worry about this?
Even though Tweens aren’t created using Instance.new, they’re still an Instance. I’ve never encountered a situation where I needed to create a Tween from inside of a RunService loop, and I wouldn’t be surprised that it’s either the cause of the problem, or related to it
Out of curiosity, are you creating a new Instance, tweening it, then destroying it each frame? If so, that would definitely tank the performance of your game. I recommend finding ways to reuse instances instead
By the way can you show the memory usage when the leak happens? Can’t you also see what’s using up the most memory in the log to identify what the issue is? I doubt its resetting because the destroy behaviour is automatically on by default.
I looked at the memory graph and it seems like luaheap seems stay the same (100 mb) but my client memory usage still went up by 30 mb. Is there something else I’m missing?
I don’t know if I’m doing something wrong, but when I paste the code given from the tutorial you sent in ServerScriptService and reset character, my camera stays in the same place my character disappears, and I can’t move.
I discovered that I didn’t destroy the raycasthitboxv4 object that I created, I just added it to janitor and it’s doing well (luaheap memory doesn’t increase every respawn)
However, the problem is that when I fight other players, the memory goes up and stays up after I respawn (the script i mentioned before goes up in memory).
I also noticed a bit of lag when I move around and dash, but my fps (when I press shift + f5) is still at a steady 60. Does anyone know why this is happening?
Essentially, it would be best to find a way to create the Tween outside of an infinite loop
I use my own janitor module, but both Janitor and GoodSignal have a good reputation. The Janitor module allows you to clean up instances as well, though
If the functions that are connected to events are anonymous, it makes it harder to identify where the memory leak is located. You’ll need to use the debug library’s profilebegin and profileend functions
Oh yeah that code that I gave wasn’t 100% complete I was just giving an idea of how to do the stuff I guess but at the time I didn’t realise the new characterdestroy behaviour feature was added.
The problem with creating a tween outside a runservice loop is that the values that change the object tweened varies. For example, a health bar udim2 size would vary based on health.
My client memory usage is usually around 1350 to 1500 mb.
Also, after a bit of digging in LuaHeap, I found that each reset, the “thread” object increases in size and count. I don’t know exactly what this means though. What I’m thinking is that somewhere in my scripts a thread isn’t being closed. Is there a way to find out where this is happening?
I understand that, but the problem is that I’m worried that memory will continue to pile up to the point where it goes over 2000 mb, making the game laggy and unplayable.
I also noticed the object “enumitem” gradually increasing. I don’t really know why enum items are increasing. Are they variables in a script or something?
My memory is about 1600-1700 when I am playing with 3-4 players, but I see other games with 20-30 players with 1200-1300 mb. I think I’m doing something wrong with my code.
The problem is that my luaheap memory stays constant while my total memory (graph) increases and doesn’t come down. This makes it almost impossible (at least that’s what I know of) to find out what is causing the leak.
Using events rather than loops is preferable, when possible. It would reduce the amount of Tweens being created, although to be honest, if health is changing very frequently, then there wouldn’t be that much of a difference between using loops
I don’t think that the tweens are responsible for the memory leak, now that I have a better understanding on how you’re using them
Another thing you should check is to make sure that you aren’t creating a connection which isn’t disconnected inside of another connection, that would definitely result in a memory leak
@himynameisKyliee2007 By the way, is the memory leak occuring when testing on the Player? If it isn’t, then it’s relatively safe to ignore, although do check on the Player again from time to time, and take note of the script so that you’ll remember where to look for the potential cause