Jump to content

Questions on the behavior of static variables


yfoo

Recommended Posts

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?

Link to comment
Share on other sites

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

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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