Sign in to follow this  
chadsxe

How do you destroy variables that are still in scope

Recommended Posts

chadsxe    146
My ap has diffrent states. Each state uses diffrent variables. Instead loading them all at the start of the program, I was wondering how to destroy them the ones that are needed any more as I move from one state to another. My question would span variables and class objects (i.e. SomeClass someclass). Any suggestions? Regards Chad

Share this post


Link to post
Share on other sites
jpetrie    13103
You don't, unless you allocated them yourself via new. If you did, you can kill them off whenever you feel like it by deleting them. However, everything else is controlled by its scope, and you don't want to mess with that or you'll cause undefined behavior.

Care to provide a more in-depth example? If each state is modelled as a different class, you only need to create and destroy an instance of the class to effectively control the lifetime of the variables in that class. There is no need to allocate them all at startup, necessarily.

Share this post


Link to post
Share on other sites

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