Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Garbage Collection (https://forums.graalonline.com/forums/showthread.php?t=75529)

cbk1994 07-15-2007 06:40 PM

Garbage Collection
 
Yumm, garbage. Someone care to explain to me what all the garbage collection features GS2 has?

Also, do references exist in GS2? For example, say you do this:
PHP Code:

= new TStaticVar(); 

So, a variable n is created; a TStaticVar() is also created, in the memory of the server/client. Let's call the memory address 102 (an example). So n holds a reference to address 102. Now what if we do this:
PHP Code:

n.var1 "blah";
n

Now will x have a reference to 102? Or does it create a new TStaticVar, and then copy the vars? What if I were to do something like this?
PHP Code:

//#CLIENTSIDE
function onCreated()
{
  
= new TStaticVar();
  
x;
  
y.var1 "blah";
  echo( 
x.var1 );


What does that echo? I can't get on RC now, and I probably won't be able to for a while.

Can anyone please clear this up for me?

Then, if I go:
PHP Code:

NULL// Not destroying the object, dropping the reference
NULL// Likewise
// Now, as all references are dropped, is the TStaticVar dropped from the memory (collected by garbage collection)? 

Thanks,
Chris Zakuto
PS: Yes, I'm a Java geek.

Inverness 07-15-2007 08:03 PM

References do exist, all object type vars are references. So y and x in your example would point to same object. And I really have no idea about garbage collection except that Stefan said he thought it was rather nice. For copying objects you would use new ObjectReference(); with a name being optional.

Admins 07-15-2007 09:12 PM

TStaticVar is called like that because it is not just a variant variable, which is just containing a single value of dynamic type.
When you assign a TStaticVar to a normal variable, then only a link to the TStaticVar is remembered. When there is no link to a TStaticVar anymore, then the variable will be deleted on the next run of the garabage collector.
In v4 the garbage collector has been improved to delete two (or more) TStaticVars which are only referencing each other. TStaticVars can only survive that when there is a global variable which is directly or indirectly linking to them.

zokemon 07-16-2007 02:10 PM

Quote:

Originally Posted by Stefan (Post 1330884)
TStaticVar is called like that because it is not just a variant variable, which is just containing a single value of dynamic type.
When you assign a TStaticVar to a normal variable, then only a link to the TStaticVar is remembered. When there is no link to a TStaticVar anymore, then the variable will be deleted on the next run of the garabage collector.
In v4 the garbage collector has been improved to delete two (or more) TStaticVars which are only referencing each other. TStaticVars can only survive that when there is a global variable which is directly or indirectly linking to them.

Wait... If I just use temp.vars for my TStaticVars then they won't work now? x_x

Inverness 07-16-2007 02:42 PM

Quote:

Originally Posted by zokemon (Post 1331244)
Wait... If I just use temp.vars for my TStaticVars then they won't work now? x_x

They would work, but after the function they would be destroyed since there are no more references, if you hadn't made any others yourself. That is, unless this has changed with v5.

cbk1994 07-16-2007 07:52 PM

What if the you did something like

PHP Code:

= new TStaticVar();
n.join"functions" );
n.start();
null

When the garbage collection is run, would it remove the TStaticVar since it holds no references, even if it is still running?

Inverness 07-16-2007 09:06 PM

The script wouldn't continue until start() is done unless it uses a trigger for something.


All times are GMT +2. The time now is 07:07 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.