suggestion: change to _MEMFREE
#4
_MEM doesn't care what order you free your memory in, just so long as you free them.  And even then, it's really only absolutely necessary when you use _MEMNEW to create a new block of memory.  All the rest of the time, your _MEM variable is just being a pointer to where something already exists.

For example, _MEMIMAGE creates a pointer which lets you access the memory of an image. _MEMFREE won't make that image go away; at most it'll just free up the mem pointer which points to it.  (And you can just reuse that pointer again in the future, with no real worries over it.)

m = _MEM(array()) <-- Same thing.  Nothing more than a pointer to where your array() is stored in memory.  Freeing that mem only frees the pointer.  The array stays just like always, unless you CLEAR/ERASE or do something else with it such as exiting the SUB/FUNCTION it was in.

But when it comes to _MEMNEW, that's when you HAVE to call _MEMFREE.  You allocated a chunk of memory for a block to use, the mem variable is the only pointer which points to that block, and it's the only way you can free that memory.   *ALWAYS* free _MEMNEW blocks when you're done with them -- and you don't have to worry about any order such as "free m1 first, before m2, before m3..."

Think of them much like opening a file.

DIM m as _MEM   <==>   OPEN file$ FOR BINARY AS #m
_FREEMEM m   <==>   CLOSE m

Just like CLOSE doesn't care what order you close your files in, _FREEMEM doesn't care either.  Free them when you get done with them -- especially if they're _MEMNEW blocks.  Wink
Reply


Messages In This Thread
suggestion: change to _MEMFREE - by OldMoses - 12-11-2022, 12:43 PM
RE: suggestion: change to _MEMFREE - by mnrvovrfc - 12-11-2022, 01:03 PM
RE: suggestion: change to _MEMFREE - by OldMoses - 12-11-2022, 01:32 PM
RE: suggestion: change to _MEMFREE - by SMcNeill - 12-11-2022, 01:57 PM
RE: suggestion: change to _MEMFREE - by Pete - 12-11-2022, 05:52 PM
RE: suggestion: change to _MEMFREE - by OldMoses - 12-11-2022, 07:54 PM



Users browsing this thread: 1 Guest(s)