Avoiding a Memory Leak

What practises should I undertake to avoid a memory leak. I’ve heard that using:

Color(10, 20, 30, 255)

Is one bad thing to do.

What else?

It’s bad only if you use it every frame (inside HUDPaint).

Basically, avoid creating objects every frame. Creating an object once and modifying it every frame is mostly OK. Pooling objects is also a good idea.

Is there any sort of garbage collection that is not extremely complicated? I’ve heard that this can help substantially in preventing crashes due to memory leaks.

Any high level language (this includes Lua) comes with a perfectly good garbage collector. You don’t need to worry.

What do you mean by this exactly? I have my ideas but I want to be sure on it.

The garbage collector is not very friendly if your script allocates thousands of objects every frame. Which is reasonable, because you should never do that.

If you know that your script is going to massively use, say, 100 vectors every frame, create the vectors at the start and reuse them when you need them. This way you’re only doing math every frame and not putting a load on the GC.

That’s what pooling objects means? Then didn’t you basically just say the same thing twice?