Jump to content
  • Advertisement
Sign in to follow this  
FDsagizi

why not execute destructor

This topic is 2409 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ? Edited by FDsagizi

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!