Deleting stacks on the fly
Sannyasin Brahmanathaswami
brahma at hindu.org
Sat Feb 11 13:38:39 EST 2017
I'm trying to optimize for minimal RAM usage on mobile. The app is modular with many stacks that are opened from the mainstack.
I had this before in a global library:
command portal_GoStack stackName
-- goes to the new stack
-- closes the current stack # But we want to delete it to clear RAM
-- safely ignores if we are alrady in the new stack
put the short name of this stack into oStackName
if oStackName = stackName then return oStackName
go to stack stackName
--close stack oStackName
-- test deleting the stacks to save on RAM
delete stack oStackName
return oStackName
end portal_GoStack
This is called from a button on a navigation bar of the stack we want to close and delete, as it opens a different stack.
This works if we just use "close stack oStackName"
but if I change this to "delete stack oStackName"
we get an error: stack "lib_SivaSivaPortal": execution error at line n/a (Object: stack locked, or object's script is executing) near "widget "go-home-portal" of group "homeScreensBottomNav" of card "images-quotes" of stack "/Users/Brahmanathaswami/Documents/_Siva-Siva-App/modules/gems/gems.livecode""
Obviously this means that the stack "gem.livecode" which has the button which is trying to "navigate" back to the home/main stack, cannot be deleted because the button script that calls the library handler is considered to be executing.
Closing it first before deleting does not help.
so I tried using "send in 10 milliseconds" And this *does* work.. I'm just trying to see if this is best practice. both stacks will occupy RAM briefly, but there is no other way that I know of to avoid this without a "flash" of some empty screen.
command portal_GoStack stackName
-- goes to the new stack
-- closes the current stack
-- safely ignores if we are alrady in the new stack
put the short name of this stack into oStackName
if oStackName = stackName then return oStackName
go to stack stackName
send "removeStack oStackName" to me in 10 milliseconds
return oStackName
end portal_GoStack
command removeStack stackName
delete stack stackName
end removeStack
Stack A opens
Stack B opens on top
Stack B want to close itself, be deleted (removed from memory) and open stack A
Anyone has gone through this loop already and discovered best practices to accomplish this?
BR
More information about the use-livecode
mailing list