Purge and global variables

Jan Schenkel janschenkel at yahoo.com
Wed Jan 15 16:13:01 EST 2003


--- Graham Samuel <livfoss at blueyonder.co.uk> wrote:
> As part of a test about preOpenStack messages, I
> have a global 
> variable which I increment by 1 every time the
> Revolution sends 
> preOpenStack to my mainstack. I was surprised to
> find that the 
> incremented value survived the destruction of the
> stack using the 
> "Purge" button in the Application Overview palette.
> I mean, it got 
> set to '1' when I first ran the code, but when I
> purged the whole 
> file and reopened it, the global came up as '2'. I'm
> up to '5' now... 
> Maybe it's something to do with the presence of the
> Revo Development 
> Environment (haven't tried it with a standalone).
> 
> Is there any official word on what is supposed to
> happen to globals? 
> I kind of assumed that at the first declaration, a
> global would be 
> empty.
> 
> Graham

Hi Graham,

You're right, the first time a global is delcared,
it's empty. But a global isn't 'purged' along with the
stack that created it -- mainly because you should be
able to use it in other stacks as well.
So this won't cause problems in a stand-alone, as the
memory is released when the program is quit, and other
programs normally can't read+write it anyway.
But under the Development Environment, it's kept in
memory until you 'delete' the global or quit RunRev
alltogether.

If you want to reset it upon closing the stack, I
suggest you trap the 'closeStack' message:

  on closeStack
    global gThatAnnoyingGLobal
    delete global gThatAnnoyingGLobal
  end closeStack

Hope this helped,

Jan Schenkel.

=====
"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com



More information about the use-livecode mailing list