Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Exit Sub from inner loop?
#9
After 1 minute:


[Image: image.png]


After a few minutes:


[Image: image.png]


And after another small wait:


[Image: image.png]

Now, what's our memory usage look like in those various screenshots?   See the issue now?

Exiting a GOSUB without a corresponding RETURN is a memory leak.  Eventually it's going to add up and cause you issues in one form or another.



Seems the website that hosts our screenshots and images is currently not working. If you try the code below and watch your task manager, you can see the endless cimb of memory.

Code: (Select All)
DO
    foo
LOOP

SUB foo
    FOR i = 1 TO 100
        GOSUB fooGosub
    NEXT
    EXIT SUB

    fooGosub:
    PRINT i
    IF i = 10 THEN EXIT SUB
    RETURN
END SUB

We start at 60MB of ram usage, then go up to 100MB and then keep climbing to 200MB, and then keep going up, up, and up endlessly until the program crashes or you start using swap file memory and writing to your hard drive... until your drive is full and THEN the whole OS probably freezes and crashes....
Reply


Messages In This Thread
Exit Sub from inner loop? - by PhilOfPerth - 02-02-2023, 09:32 AM
RE: Exit Sub from inner loop? - by SMcNeill - 02-02-2023, 09:43 AM
RE: Exit Sub from inner loop? - by PhilOfPerth - 02-02-2023, 10:39 AM
RE: Exit Sub from inner loop? - by OldMoses - 02-02-2023, 04:10 PM
RE: Exit Sub from inner loop? - by PhilOfPerth - 02-02-2023, 11:09 PM
RE: Exit Sub from inner loop? - by PhilOfPerth - 02-02-2023, 11:48 PM
RE: Exit Sub from inner loop? - by SMcNeill - 02-03-2023, 12:04 AM
RE: Exit Sub from inner loop? - by PhilOfPerth - 02-03-2023, 12:56 AM
RE: Exit Sub from inner loop? - by SMcNeill - 02-03-2023, 02:13 AM
RE: Exit Sub from inner loop? - by PhilOfPerth - 02-03-2023, 02:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Exiting sub while inside a loop PhilOfPerth 5 525 12-05-2025, 09:40 AM
Last Post: PhilOfPerth
  Do Loop, Sleep and Mouse Button Dimster 5 599 09-06-2025, 12:57 PM
Last Post: Dimster
  Using modulo to loop through lists fistfullofnails 3 726 09-03-2025, 11:50 PM
Last Post: fistfullofnails
  What is wrong with this for/next loop Helium5793 6 1,164 04-15-2025, 05:11 PM
Last Post: Kernelpanic
  Question on ln in a for/next loop Dimster 13 2,251 09-13-2024, 11:07 PM
Last Post: Kernelpanic

Forum Jump:


Users browsing this thread: 1 Guest(s)