Data Realms Fan Forums
http://45.55.195.193/

Garbage Collection
http://45.55.195.193/viewtopic.php?f=73&t=18544
Page 1 of 3

Author:  TheLastBanana [ Tue Apr 20, 2010 2:59 am ]
Post subject:  Garbage Collection

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-collectgarbage
We 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.

Author:  CrazyMLC [ Tue Apr 20, 2010 3:28 am ]
Post subject:  Re: Garbage Collection

Address?

Author:  salt_1219 [ Tue Apr 20, 2010 3:38 am ]
Post subject:  Re: Garbage Collection

+100 internets, no +10,000... Hell I would buy him a ton of chocolate for this.
Have you tried it out? I curious how much better things will run.

Author:  Warguy [ Tue Apr 20, 2010 3:47 am ]
Post subject:  Re: Garbage Collection

Forget a chocolate bar.

Hell, get the world's biggest chocolate bar and give it to him.

Author:  TorrentHKU [ Tue Apr 20, 2010 3:48 am ]
Post subject:  Re: Garbage Collection

I assume that you'll be implementing this into the computer, and any other Lua intensive mods?

Author:  linkfan23 [ Tue Apr 20, 2010 3:55 am ]
Post subject:  Re: Garbage Collection

If the script is running on one object does it apply to all objects on the screen? If so then someone needs to make a brain that has the script.

Author:  Grif [ Tue Apr 20, 2010 3:56 am ]
Post subject:  Re: Garbage Collection

Yes, if you run garbage collection it'll run through all memory used by the game.

Author:  TorrentHKU [ Tue Apr 20, 2010 4:09 am ]
Post subject:  Re: Garbage Collection

Could someone just make a quick script and post it, so we Lua illiterate can stick it on the vanilla Brain or whatever else?

Author:  TheLastBanana [ Tue Apr 20, 2010 4:15 am ]
Post subject:  Re: Garbage Collection

The FBM and Deathwasps both have this integrated now.
Here's a script for you to stick on your brain:
Code:
function Create(self)
   self.garbTimer = Timer();
end

function Update(self)
   if self.garbTimer:IsPastSimMS(10000) then
      collectgarbage("collect");
      self.garbTimer:Reset();
   end
end

Author:  CrazyMLC [ Tue Apr 20, 2010 4:16 am ]
Post subject:  Re: Garbage Collection

What 'garbage' is it cleaning up, anyway?

Author:  whitty [ Tue Apr 20, 2010 4:21 am ]
Post subject:  Re: Garbage Collection

My God... No amount of chocolate is enough for you.


THIS is why we need documentation on everything. *cough cough*

Author:  Duh102 [ Tue Apr 20, 2010 4:23 am ]
Post subject:  Re: Garbage Collection

CrazyMLC wrote:
What 'garbage' is it cleaning up, anyway?

Variables that are no longer referenced by anything mostly.

Author:  CrazyMLC [ Tue Apr 20, 2010 4:24 am ]
Post subject:  Re: Garbage Collection

OMG
Just tried the new and improved Computer.
Lag free.
Lag FREE.

Buckets of chocolate.
Buckets.

Author:  whitty [ Tue Apr 20, 2010 4:25 am ]
Post subject:  Re: Garbage Collection

Basically, stuff that has been used already that is now only taking up space and slowing the game down.

Author:  dragonxp [ Tue Apr 20, 2010 4:26 am ]
Post subject:  Re: Garbage Collection

Another Milestone in CC.

Its not perfect, but i can play with the FBM without it crashing when i crush 1 guy.

Page 1 of 3 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/