Additional Topics > External Development Guide > IDLInternals - Variables > Freeing Dynamic Resources

# Freeing Dynamic Resources

In addition to performing its primary function, IDL_StoreScalar() and IDL_StoreScalarZero() have two very useful side effects:

1. Storing a scalar value in a variable causes IDL to free any dynamic memory currently used by that variable.
2. These routines do the required error checking to make sure the variable allows a new value to be stored into it before performing the actual storage operation.

Often, a system routine accepts an input argument that will have a new value assigned to it before the routine returns to its caller, and the initial value of that argument is of no interest to the routine. Storing a scalar value into such an argument at the start of the routine will automatically check it for storability and free unnecessary dynamic memory. In one easy operation, the required error checking is done, and you’ve improved the dynamic memory behavior of the IDL system by minimizing dynamic memory fragmentation. For example:

IDL_StoreScalarZero(&v, IDL_TYP_LONG);

Error handling is discussed further in IDL Internals: Error Handling.