Jump to content

Questions on the behavior of static variables


Recommended Posts

Posted

1. I've notived that static variables seem to persist after restarting a script. Would setting these variables to null under onExit() wipe them for the next time the script is started?

2.) Are static variables shared among different instances of the same script? If I use a static to make a global variable, is that variable global to every running instance of a script or just that specific instance?

Posted
19 minutes ago, PayPalMeRSGP said:

1. I've notived that static variables seem to persist after restarting a script. Would setting these variables to null under onExit() wipe them for the next time the script is started?

2.) Are static variables shared among different instances of the same script? If I use a static to make a global variable, is that variable global to every running instance of a script or just that specific instance?

1. Yes if you were to change the value of the variable that persists then of course it will retain the null value for next time the script is started.

2. The variable would be script specific for a given instance unless you coded it to be shared amongst scripts that were connected in some way.

  • Like 1
Posted
21 minutes ago, PayPalMeRSGP said:

1. I've notived that static variables seem to persist after restarting a script. Would setting these variables to null under onExit() wipe them for the next time the script is started?

2.) Are static variables shared among different instances of the same script? If I use a static to make a global variable, is that variable global to every running instance of a script or just that specific instance?

https://stackoverflow.com/questions/453023/are-static-fields-open-for-garbage-collection

  • Like 1

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...