View Single Post
  #2  
Old 10-11-2010, 12:26 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Quote:
Originally Posted by Tigairius View Post
Serverside temporary TStaticVars are not being cleared from memory apparently.

Example:
PHP Code:
function myFunc() {
  
temp.= 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.
__________________
Skyld
Reply With Quote