Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

Release

This command sends memory variables into oblivion, freeing up the memory they occupy.

Usage

RELEASE ALL [ EXTENDED | LIKE Skeleton | EXCEPT Skeleton ]
RELEASE MemvarList

You’ll rarely use this command for private or local scalar (non-array) variables. They’re automatically released when the routine that creates them finishes. It’s a little more common to release local or private array variables so you can re-create them with new dimensions. Since you can do that with DIMENSION, usually you release an array only when you’re using it with a command or function that doesn’t automatically redimension its result, like COPY TO ARRAY.

Public variables are another story. They stick around until you explicitly release them. RELEASE ALL doesn’t release public variables in programs (though it does from the Command Window). Use the EXTENDED clause to release public variables, as well as the others, in programs.

The EXTENDED, LIKE and EXCEPT clauses don't much like each other. Only the first one you specify is honored. You can't RELEASE ALL EXTENDED LIKE hack*. This limit doesn't bother us that much because we rarely, if ever, use public variables in programs.

This limit applies even when you're not dealing with public variables. You can't RELEASE ALL LIKE n* EXCEPT nCount, which is a shame.

However, it's not the behavior that really bothers us. After all, it is documented that way. What makes this a bug in our eyes is that it doesn't tell you it's ignoring you.

You should release a variable before you make it public—just in case. PUBLIC declarations trigger an error if a local or private variable already exists with that name in that scope.

Example

NOTE: This only works as a program, not if the commands ;
      are typed in from the command window.
LOCAL a1, a2, a3, b1, b2, c1, c2, c3, x
PUBLIC a4, b3
* Now do something with them
RELEASE ALL LIKE b*
DISPLAY MEMORY  && b1 and b2 are gone; b3 is not
RELEASE ALL EXTENDED
DISPLAY MEMORY  && all gone

See Also

Clear All, Clear Memory, Local, Private, Public