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.

CLEAR DLLs

This one is supposed to remove declared DLL functions from memory. Surprise, it works.

Usage

CLEAR DLLS [ DLLList ]

We have mixed feelings about this one. First, DLL Declares are supposed to take up a really small amount of memory, so clearing them doesn’t make much sense from that standpoint. Second, if you are dealing with any objects that DECLARE the DLLs in their Inits, and then ASSuMe that these declarations will be around later to play with, blam, you just blew them out of the water. The solution, of course, is to encapsulate the declaration, use and clean up into a single method, so that you leave things as you found them.

However, VFP 7 addressed our biggest issues with this command. We can now specify which functions to clear and, more importantly, using ADLLS(), we can find out what functions are already declared. So, in the rare cases where it makes sense, we can handle these declarations intelligently.

Della points out that CLEAR DLLs makes the most sense in large applications with multiple modules. The command (together with ADLLS()) gives you a way for one module to get its hands on every bit of available memory, but still clean up after itself, so other modules don’t blow up.

Example

LOCAL nDLLCount, aDLLList[1], nRow, cAlias

nDLLCount = ADLLS( aDLLList )
nRow = ASCAN( aDLLList, "DangerousFunction", -1, -1, 1, 15)
IF nRow > 0
   cAlias = aDLLList[ nRow, 2]
   CLEAR DLLS &cAlias
ENDIF

The example demonstrates two key points about CLEAR DLLs. First, it expects the alias with which the function was declared, not the name. Second, it expects the alias to be hard-coded. To use a variable, you need a macro. Name expansion (with parentheses) doesn’t work here.

See Also

ADLLs(), Declare-DLL