02-03-2023, 02:40 AM
(This post was last modified: 02-03-2023, 02:52 AM by PhilOfPerth.)
(02-03-2023, 02:13 AM)SMcNeill Wrote: After 1 minute:
After a few minutes:
And after another small wait:
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....
Ahah, got it!
CPU usage stays the same, but memory used climbs, presumably to crash at some stage.
But I think I'm still ok to exit early if no other calls are involved, i.e. the sub has not called another sub or process that's still active?
Wrong! I see it still creeps up in my example.
I guess I'll have to be careful how I exit. Thanks.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.)
Please visit my Website at: http://oldendayskids.blogspot.com/
Please visit my Website at: http://oldendayskids.blogspot.com/