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



Users browsing this thread: 2 Guest(s)