So, our fine friend Kalidor
pointed out to me that all this memory leakage should be possible to manually fix. Hogwash, most would say.
But hey.
Apparently he was right.
I had entirely forgotten that Lua has built-in garbage collection, and in fact I didn't realize that it could be called Lua-side, I was pretty sure it was a hardcoded thing.
Turns out Data has some very odd implementation of it. Try sticking this into the top of an update function for any piece of code:
Code:
print(collectgarbage("count"));
This outputs the number of kilobytes Lua is using. Watch the number rise and rise and rise until some point, what appears to be about 2 minutes later (according to the game's skewed sense of time), it resets back to somewhere in the 25000s. So, all we have to do is make it go faster. Much faster.
Take a peek at the function:
http://www.lua.org/manual/5.1/manual.html#pdf-collectgarbageWe could restart the collector in the create function, but it's probably best to manually call it just in case there are some strange compilation settings Data has on the collector.
So, throw a timer in your script, and when it passes 10000 (10 seconds), call collectgarbage("collect") and reset the timer.
Done, your scripts are more efficient.
Somebody buy Kalidor a box of chocolate.