Quote:
Originally Posted by Tigairius
Serverside temporary TStaticVars are not being cleared from memory apparently.
Example:
PHP Code:
function myFunc() { temp.v = new TStaticVar(); temp.v.join("myclass"); sleep(0.1); return temp.v; }
After this function is called, the temp.v stays in memory and doesn't appear to get destroyed. This is a big problem for me.
|
In your example why would you want it cleared from memory? It seems like you are trying to return a reference to be used elsewhere.
I'm guessing this is expected behaviour; TStaticVars will probably be allocated on the heap and not the stack, and sending a reference to it by
return is probably instructing the garbage collector to preserve it in memory because it's expected lifetime is no longer clear (i.e. now the object is expected to outlive the function execution). In scenarios like this, you are normally expected to destroy an object yourself when you are finished with it since it is difficult for the garbage collector to determine whether you still want it or not.