View Single Post
  #4  
Old 10-11-2010, 07:17 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by Skyld View Post
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.
Quote:
Originally Posted by Stefan View Post
The TStaticVar will be destroyed once no one else is referencing the object anymore. A reference in a temp.var is still a reference. It's automatically detecting 'circle references'.
Hmm, I think I see what you are saying. I'll have to destroy it elsewhere. But what about the issue with joining classes? Is there any way this could be addressed?
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote