Sign in to follow this  

why not execute destructor

This topic is 2038 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![img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
[CODE]
class A
{
A(){ output( "CON" ); }
~A(){ output( "DES" ); }
}
void startGame( string &param )
{
A a;
}
output:
CON
DES
[/CODE]
Ok, next code:
[CODE]
class A1{ }
class A
{
A(){ output( "CON" ); }
~A(){ output( "DES" ); }
A1 @en;
}

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

output:
CON
[/CODE]

why not execute destructor ? Edited by FDsagizi

Share this post


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

This topic is 2038 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this