The title basically explains it all. But if you still dont get it. Basically…
I recently noticed that LoadAnimation() has a destroy method. Does this mean i need to destroy the loaded one everythime i dont need it?? i know you need to destroy the actual animation instance. But the loaded ones im a bit worried about?
AnimationTracks are still instances so they adhere to the same principles as other instances - that is, don’t hold strong references if you don’t want memory leaks. You should be destroying AnimationTracks if you don’t need them anymore. Connections and other strong references to the track can keep the instance alive when you don’t want.
The sample in the OP shouldn’t leak memory because when the scope closes the local variable is cleaned up and there’s no more references to the AnimationTrack.
AnimationTrack (usually) barely weights anything - this doesn’t really affect Roblox, except scenarios when you have many animations loaded (I mean not just 50 or 70, but more than 130 - I tested, this started affecting my RAM and GPU very much).
But Roblox server themselves are pretty strong to hold this much resources idk if i wrote this correct - plus the fact they have optimization.
Doesn’t matter really. Most instances and other memory-consuming entities in the engine don’t cost that much alone. It’s not the individual instances that you need to think about but the overall picture and everything added together. Memory leaks are a summary of all memory management problems not necessarily owed to a single type of instance. That and it’s good practice to destroy instances you don’t need anymore regardless. Optimisation, available memory and the cost of instances don’t play a factor in good practice and taking proper steps to manage your instances.