Replacing a stack

J. Landman Gay jacque at hyperactivesw.com
Tue Oct 23 01:55:41 EDT 2007


Shari wrote:

> Is there any chance that a stack remains in memory and that Rev 
> recreates it without my code telling it to?

Rev won't recreate a stack without specific instructions to do so, but 
there is a chance that the stack remains in memory when you may not 
expect it.

> repeat with x = 1 to the number of cds of stack prefStack
>         set the cantDelete of cd x of stack prefStack to false
>       end repeat

Unless something else in the script requires this, it's probably 
unnecessary, since you can delete a whole stack in one go regardless of 
individual card settings.

>       if "UserPrefs" is in the stacksInUse then
>         stop using stack "UserPrefs"
>         delete stack "UserPrefs"
>       end if
>       if "UserPrefs" is in the openstacks then
>         close stack "UserPrefs"
>         delete stack "UserPrefs"
>       end if

If the stack is closed but its destroystack property is false, the stack 
will remain in memory. The openstacks test here will never run.

>       wait 10 ticks # giving it a chance to fully finish
>       delete file prefStack
>       wait 30 ticks # giving it a chance to fully finish
>       answer "File deleted" # so that I can verify in the Prefs folder
>     # that the file is actually deleted
>       put decompress(the stackData of stack myAppStack) into s
>       put s into url ("binfile:" & prefStack)
>       save stack prefStack

The last line here may be the problem. It isn't necessary to save a file 
that you've created with the url keyword; the file is automatically 
saved as it is written to disk. In this case, if the prefs stack is 
still in memory (because its destroystack property is false) then saving 
it will overwrite your new file with the old one still in memory. I'd 
remove the "save stack prefStack" line entirely and see if that solves it.

I'd also set the destroystack of the prefs stack to true, otherwise it 
may hang around when you don't expect it. You'll also need to do what 
Jeanne suggested: issue the "revert" command so that the newly written 
stack will be loaded into memory, replacing the old one.

BTW, I don't think you need any of the wait statements. Rev does not 
proceed to the next line of script until the current line has finished 
executing (with a few very exotic exceptions, none of which I can think 
of right now.) None of the lines in your script need any particular 
delay time.

Actually, now that I think about it, you may be able to replace all the 
above with just this:

   if "UserPrefs" is in the stacksInUse then stop using stack "UserPrefs"
   delete file prefStack
   put decompress(the stackData of stack myAppStack) into \
      url ("binfile:" & prefStack)
   revert stack "UserPrefs" -- reloads the new one
   start using stack "UserPrefs" -- if you want


-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com



More information about the use-livecode mailing list