View unanswered posts | View active topics It is currently Sat Jan 11, 2025 1:26 pm



Reply to topic  [ 32 posts ]  Go to page 1, 2, 3  Next
 Garbage Collection 
Author Message
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post 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.


Tue Apr 20, 2010 2:59 am
Profile WWW
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post Re: Garbage Collection
Address?


Tue Apr 20, 2010 3:28 am
Profile WWW
User avatar

Joined: Tue Jan 12, 2010 8:25 pm
Posts: 400
Location: mukilteo, wa
Reply with quote
Post 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.


Tue Apr 20, 2010 3:38 am
Profile
User avatar

Joined: Tue Apr 06, 2010 4:33 pm
Posts: 276
Reply with quote
Post Re: Garbage Collection
Forget a chocolate bar.

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


Tue Apr 20, 2010 3:47 am
Profile
Loose Canon
User avatar

Joined: Sun Mar 29, 2009 11:07 pm
Posts: 2992
Location: --------------->
Reply with quote
Post Re: Garbage Collection
I assume that you'll be implementing this into the computer, and any other Lua intensive mods?


Tue Apr 20, 2010 3:48 am
Profile WWW
User avatar

Joined: Sun Oct 11, 2009 4:48 am
Posts: 133
Reply with quote
Post 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.


Tue Apr 20, 2010 3:55 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Garbage Collection
Yes, if you run garbage collection it'll run through all memory used by the game.


Tue Apr 20, 2010 3:56 am
Profile
Loose Canon
User avatar

Joined: Sun Mar 29, 2009 11:07 pm
Posts: 2992
Location: --------------->
Reply with quote
Post 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?


Tue Apr 20, 2010 4:09 am
Profile WWW
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post 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


Tue Apr 20, 2010 4:15 am
Profile WWW
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post Re: Garbage Collection
What 'garbage' is it cleaning up, anyway?


Tue Apr 20, 2010 4:16 am
Profile WWW
User avatar

Joined: Sat Jun 16, 2007 2:31 am
Posts: 2982
Location: Texas
Reply with quote
Post Re: Garbage Collection
My God... No amount of chocolate is enough for you.


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


Tue Apr 20, 2010 4:21 am
Profile
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post Re: Garbage Collection
CrazyMLC wrote:
What 'garbage' is it cleaning up, anyway?

Variables that are no longer referenced by anything mostly.


Tue Apr 20, 2010 4:23 am
Profile
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post Re: Garbage Collection
OMG
Just tried the new and improved Computer.
Lag free.
Lag FREE.

Buckets of chocolate.
Buckets.


Tue Apr 20, 2010 4:24 am
Profile WWW
User avatar

Joined: Sat Jun 16, 2007 2:31 am
Posts: 2982
Location: Texas
Reply with quote
Post Re: Garbage Collection
Basically, stuff that has been used already that is now only taking up space and slowing the game down.


Tue Apr 20, 2010 4:25 am
Profile
User avatar

Joined: Wed Sep 09, 2009 3:16 am
Posts: 3032
Location: Somewhere in the universe
Reply with quote
Post 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.


Tue Apr 20, 2010 4:26 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 32 posts ]  Go to page 1, 2, 3  Next

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.034s | 13 Queries | GZIP : Off ]