How To

How to prevent 'random' "OUT OF MEMORY" error?


nousername010 2022-06-24 13:03

Was browsing through old projects of mine and many other users. I noticed that no matter how different the projects, some projects share the "OUT OF MEMORY" error if played for too long. I rarely encounter this error due to the length of most projects, but what exactly causes this, and how to prevent it? Planning to make something complex and I'm worried something similar might happen.

nathanielbabiak 2022-06-24 14:28 (Edited)

The console emulator allocates RAM for variables (and tracks program flow) in a space that's inaccessible to the console code.

I recall running some tests a long time ago on 'out of memory' errors (but I didn't keep the results), and those tests, when re-run on v1.2, seem to yield the error sooner.

There's two things to avoid: recursion and GOTO. Those are supported by the console, but not robustly. Recursion is limited to 128 times, and GOTO might(*) have some issue with jumps across control structures.

(*I haven't reproduced any errors with GOTO, this is just a general sense I get based on what's uploaded.)

Timo 2022-06-24 21:14

I can check this later in detail, but I also think that jumping out of a Subroutine or Subprogram using GOTO can fill the stack memory.

Timo 2022-06-25 13:53

Never use GOTO to exit from a SUB.

If you want to go somewhere else after GOSUB without returning back, use RETURN LABEL instead of GOTO LABEL.

nousername010 2022-06-26 00:15

I see, thanks guys! I'll try to experiment with what you said, as well as limit my temp variable usage to see if it has any impact on the active RAM

SP4CEBAR 2022-06-28 13:39

That's called a memory leak, I had to learn it the hard way

Log in to reply.