Push/Pop Card versus Goto Card

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

allengwinn
Posts: 37
Joined: Tue Aug 21, 2012 4:46 pm

Push/Pop Card versus Goto Card

Post by allengwinn » Sat Dec 29, 2018 10:29 pm

Is there a reason to use Push and Pop versus just a bunch of Goto's when moving from card to card without worrying about memory leaks? In other words, if I have a Main card with a button that launches another card and a button on that card that launches another card (etc.) but then have a "Home" button on each card that just does a Goto back to the Main card, am I inviting disaster or is that completely kosher? Is there something that should be used on exit from a card to destroy the memory it's using?

Sorry, I just come from a structured coding environment :)

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Push/Pop Card versus Goto Card

Post by FourthWorld » Sat Dec 29, 2018 10:40 pm

All coding is structured. Languages differ only in how they're structured. :)

The "go" command (LC has no "goto") allows navigation to any card or stack.

The "push" and "pop" commands can be used for the subset of navigation where you specifically want to traverse a set of cards in inverse storage order.

Personally I almost never use "push" and "pop", but it may be just a matter of style. I just don't often have cases fitting what they do, and prefer to manage navigation more directly anyway.

Both options are likely very similar with regard to memory requirements. Command execution by itself adds little to the engine once the stack is loaded, with most memory being take up by media on cards and the rendering buffer for those cards. So either method will for the most part have the same RAM footprint.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Push/Pop Card versus Goto Card

Post by bogs » Sat Dec 29, 2018 11:53 pm

FourthWorld wrote:
Sat Dec 29, 2018 10:40 pm
The "go" command (LC has no "goto") allows navigation to any card or stack.
Well, it doesn't have "goto" as one word, anyway :wink:
Selection_003.png
Go...to?
Only kidding ! Although, that is how I write it, I am probably alone in that group. I don't use any of the other abbreviations either. Don't ask, I can't explain it.
Image

allengwinn
Posts: 37
Joined: Tue Aug 21, 2012 4:46 pm

Re: Push/Pop Card versus Goto Card

Post by allengwinn » Sun Dec 30, 2018 2:32 am

Yeah, I was worried about memory leaks if you started doing too many "go to" :) cards. So if I repeatedly "go to" a main menu, I'm not increasing app storage... that's what I'm trying to determine. I'm writing an app that will make repeated visits to the main menu so I'm trying to be socially responsible :)

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Push/Pop Card versus Goto Card

Post by bogs » Sun Dec 30, 2018 2:20 pm

I think Hermann figured out how to get a memory leak with his latest experiment, but so far as I know, that is a self contained and specific circumstance. -hh's stuff really is over the top (and my head) :D
Image

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Push/Pop Card versus Goto Card

Post by FourthWorld » Sun Dec 30, 2018 6:08 pm

When a stack file has been loaded into memory, the only additional memory needed is for rendering the card. Unless you have a large number of high res images, you probably won't see much impact on memory at all.

Any complex software has the potential for memory leaks, and LiveCode is no exception. But since LiveCode is used in many long-running contexts like industrial control systems, kiosks, etc., the core team gives high priority to fixing leaks when they're reported, and uses automated code review tools like Coverity to catch things like that during development before it's released.

I've had software made with LiveCode that's running continuously, performing tasks every five minutes, for several weeks at a time without a hiccup, and that's on very modest hardware with just 1GB RAM. I could probably run it for months, but I keep the system up to date and sometimes OS patches require reboot.

At the moment, I'm not aware of any leaks that have not been resolved, or at least in process to be resolved for the next release.

Should you find one please report it. But they're rare enough that you shouldn't need to worry about them when designing your app.

If you need to open a card, open the card. You'll be fine, regardless which syntax you use to open it.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Push/Pop Card versus Goto Card

Post by FourthWorld » Sun Dec 30, 2018 6:15 pm

bogs wrote:
Sun Dec 30, 2018 2:20 pm
I think Hermann figured out how to get a memory leak with his latest experiment, but so far as I know, that is a self contained and specific circumstance.
Do you recall how recent that was, and whether it was reported?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Push/Pop Card versus Goto Card

Post by bogs » Sun Dec 30, 2018 11:04 pm

Well, as to how recent, it was part of this post in his "Succesful Test" area.
[-hh] wrote:
Fri Dec 28, 2018 5:39 am
JIGSAW PUZZLE 2d-video v_100
<sic>
Videos.
As above but without importing, use one of the nine built-in looping videos.
The segmenting of the video frames is done with canvas methods in javascript.
This will stress your CPU/GPU! It runs at about ten times faster in
the IDE with a browser widget, but sadly this is memory-leaking (5 MBytes
per second).
The HTML5 standalone runs at about two times faster in Safari
than Firefox or Chrome/Opera. Reduce the number of pieces if you have less
than 2-3 frames per second.
</sic>
As to whether or not he reported it, or is just going to fix it hisself, thats one I'll leave to the man who found it to answer :wink:
Image

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Push/Pop Card versus Goto Card

Post by FourthWorld » Mon Dec 31, 2018 1:08 am

bogs wrote:
Sun Dec 30, 2018 11:04 pm
Well, as to how recent, it was part of this post in his "Succesful Test" area.
[-hh] wrote:
Fri Dec 28, 2018 5:39 am
JIGSAW PUZZLE 2d-video v_100
<sic>
Videos.
As above but without importing, use one of the nine built-in looping videos.
The segmenting of the video frames is done with canvas methods in javascript.
This will stress your CPU/GPU! It runs at about ten times faster in
the IDE with a browser widget, but sadly this is memory-leaking (5 MBytes
per second).
The HTML5 standalone runs at about two times faster in Safari
than Firefox or Chrome/Opera. Reduce the number of pieces if you have less
than 2-3 frames per second.
</sic>
As to whether or not he reported it, or is just going to fix it hisself, thats one I'll leave to the man who found it to answer :wink:
Curious. Being specific to the browser object, it seems the leak is in that third-party component. Probably good to report it if it's repeatable, but it may have to go upstream to the browser engine vendor.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

ValiantCuriosity
Posts: 128
Joined: Thu Jun 30, 2016 3:08 am

Re: Push/Pop Card versus Goto Card

Post by ValiantCuriosity » Sun Mar 03, 2019 8:08 pm

LC Gurus, Please check my thinking:

These commands have quite confused me. I was thinking that "Push" was supposed to work globally over the entire Stack/App.

It seems like it is a shame that "Push" doesn't reside in a LC global memory for the entire stack/app. That way, we could access any card by simply referencing the "Push" command once on some card. It would be "remembered" throughout the Stack.

Then, if it was remembered, all I'd have to do is issue a "Pop" command any place and on any card that I wanted to "Pop" back to that particular card.

AFAIKT, the way it is implemented in LC, simply gives coders another option to the" go card" command.

Happy Dancing with LC here. :idea:
-Rachel
May I never be cured of my curiosity! :D

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Push/Pop Card versus Goto Card

Post by bogs » Sun Mar 03, 2019 8:48 pm

ValiantCuriosity wrote:
Sun Mar 03, 2019 8:08 pm
AFAIKT, the way it is implemented in LC, simply gives coders another option to the" go card" command.
I see them as two pretty specifically different types of things, i.e.
* 'go' will go to any card of any stack that is in memory, or part of the stackfiles list.
* 'push' puts the long id of a card into a list, and 'pop' retrieves and removes them from the list in the order they are listed.

No doubt 'go' is what you will use most often, but I can see the use-case for 'push/pop'.

As to your thoughts on the 'global referenced list', it would probably be easiest to put the card references in a custom property of the main stack (or anywhere, really), and then reference that custom property list from anywhere.
Image

ValiantCuriosity
Posts: 128
Joined: Thu Jun 30, 2016 3:08 am

Re: Push/Pop Card versus Goto Card

Post by ValiantCuriosity » Sun Mar 03, 2019 11:51 pm

@Bogs
That clarification helped. I'm still somewhat confused as usual, but I'm getting somewhere and, for a change, I'm enjoying the scripting experience.

Thanks,
-Rachel
May I never be cured of my curiosity! :D

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Push/Pop Card versus Goto Card

Post by bogs » Sun Mar 03, 2019 11:55 pm

Good to hear that your enjoying the experience! Cooking up a side project that will, hopefully, be of some benefit to the (newer) community at large, but you'll probably be a pro scripter before it is of any use to you :wink:
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Push/Pop Card versus Goto Card

Post by jacque » Mon Mar 04, 2019 6:18 pm

The push list is global for the whole session. There is also a global recentCards list.

Push places the current card at the top of the push list. Pop peels off the top entry and goes there. If you push the same card twice in succession, you'll need to pop it twice to get it off the list. It will look like nothing happened because the second pop won't change cards. The push list is LIFO.

The recentCards list is similar, but is kept automatically without any scripting required. It's also LIFO. The current card is the top entry and every other visited card is listed below that in reverse order, from more recent down to the oldest. Line 2 of the recentCards tells you which card you just came from.

The main difference between the two is that the push list is a curated list of cards you designate. The recentCards is everywhere you've been. Another difference is that pop actually navigates to the card, where the recentCards is just a reference and you can do whatever you want with the information.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

ValiantCuriosity
Posts: 128
Joined: Thu Jun 30, 2016 3:08 am

Re: Push/Pop Card versus Goto Card

Post by ValiantCuriosity » Mon Mar 04, 2019 7:46 pm

If you push the same card twice in succession, you'll need to pop it twice to get it off the list. It will look like nothing happened because the second pop won't change cards. The push list is LIFO.
Well, now I see why it wasn't working for me. I wish that I could just put "Pop" on each card and automatically pop back to the card that was pushed every time... (Lazy me)

I'm really not planning on using these commands. At some point, maybe I'll need them, and though I have many memory leaks, I might get lucky enough to say, "Oh, I think there is a command for that." :D

Thanks Jackie.

-Rachel
May I never be cured of my curiosity! :D

Post Reply

Return to “iOS Deployment”