I’d urge you to scour the devforum because that’s entirely how I learned - there’s almost zero official documentation on the subject. I guess Roblox doesn’t expect the average developer to run into those types of situations.
When you create any object you don’t plan to keep around forever - maybe a bullet, maybe a visual effect, or maybe your own character - when the object is destroyed, lua’s routine garbage-collection system will free up the memory used to locate/render the object - but only if no strong references exist to the object.
Strong references can be variables, functions, connections, etc.
Anything that tells lua ‘hey, this exists’ will prevent garbage collection from freeing up the memory it inhabits.
Generally, though, those circumstances are rare. Variables isolated to a scope - such as local variables inside functions or loops - lose reference once that scope ends. Variables created outside of scopes are still contained within the scope of the entire script, so once that script stops running (think of a localscript inside a character, like your default Animator), the variables created within it lose reference as well. You don’t need to set unused variables to nil, as they’ll be treated as nil once they lose reference.
The most common offenders - at least in my own practice - are connections that never break and tables that are never cleared. Even if a script stops running, connections are objects just like a part or a sound - they remain in memory until they’re broken, either manually, or because the object the connection was attached to was destroyed, such as a Touched event on a bullet being broken because the bullet was destroyed.
And if those connections aren’t broken, anything they reference within them will ALSO stay in memory.
Again, I’d do your own research because it definitely pays to do so, but I think your own code should be fine. If you’re suspicious, use the F9 console in studio and observe the Instances entry in the Server tab on the memory section. See if any interaction in your game causes a permanent rise in memory consumption, and then isolate it.