Advertisement

why not execute destructor

Started by May 13, 2012 09:58 AM
0 comments, last by WitchLord 12 years, 6 months ago
Hello!smile.png

class A
{
A(){ output( "CON" ); }
~A(){ output( "DES" ); }
}
void startGame( string &param )
{
A a;
}
output:
CON
DES

Ok, next code:

class A1{ }
class A
{
A(){ output( "CON" ); }
~A(){ output( "DES" ); }
A1 @en;
}

void startGame( string &param )
{
A a;
}

output:
CON


why not execute destructor ?
Because the object has a handle as member it has a chance of forming a circular reference with itself. For this reason the garbage collector will hold on to a reference to be able to resolve these circular references if necessary.

This also means the destruction of the object will be delayed until the garbage collector runs. Only then will the destructor be called.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement