Top > Lycia reference > Querix 4GL > Statements > FREE
To meet your needs, we constantly work to improve Querix products.
This means that Lycia documentation is developing as well.
In case you have found a certain dissonance between the provided information and the actual behavior of Lycia 3 and/or your applications, please, let us know about this via documentation@querix.com so that we can introduce the necessary changes to our documentation.
Thank you for your attention and cooperation.
FREE statement is an SQL statement, that can be directly embedded into the 4GL source code. It is used to release resources allocated to a cursor, a prepared statement or a variable of a large data type (TEXT or BYTE, in particular).
If used to release resources allocated to a cursor, the FREE statement has the following syntax:
FREE cursor_name
The total number of the open cursors, that are allowed for a single process at a time, is limited by an amount of the system memory available.
Once freed, the cursor cannot be used by any other statement. To use a closed cursor again, you should reopen it: declare the cursor once more within the source code. Note, that the cursor which has not been explicitly closed cannot be freed.
Releasing Resources Allocated to a Cursor
To free the resources allocated to a cursor, declared with the help of a CURSOR variable, the Free() method should be called. It takes no arguments and returns a value of sqlca.sqlcode on its invocation:
CALL cur.Free()
After the statement above has been executed, the cursor cannot be opened and used again within the application.
The Free() function is implicitly invoked when all the references to the cursor object are closed.
FREE statement followed by the name of a prepared statement releases the resources that the program has allocated to this prepared statement:
FREE prepared_stmt_id
After the FREE statement has been executed, the statement identifier specified in it cannot be referenced by the EXECUTE and the DECLARE cursor statements, until the same or another statement is linked to this identifier once again within an application source code.
If the FREE statement is applied to a prepared statement which is not associated with a cursor, it frees the resources in both a database server and an application development tool. If a prepared statement is associated with a cursor, the structure like FREE stmt _id can releases only the resources of an application development tool. The database server resources can be freed only under condition that the cursor is freed.
Releasing Resources Allocated to Prepared Statements
To free the resources associated with a prepared statement by defining a PREPARED variable, the Free() method is typically used. It takes no arguments and returns a value of sqlca.sqlcode on its invocation:
CALL variable_name.Free()
After the Free() method has been executed, the statement you prepared with a variable of the PREPARED data type cannot be referenced again without preparing it repeatedly by means of the Prepare() method.
FREE statement followed by the name of a variable of the TEXT or BYTE data type releases resources allocated for the specified variable data storage:
FREE text/byte_var_name
Depending on the place of the TEXT or BYTE variable location, the runtime system may release the memory or delete a file intended to store the data.
The resources for the variables of a local scope are freed automatically on returning from the MAIN or function blocks during an application execution.
After the FREE statement has been declared, the specified TEXT or BYTE variable cannot be used again until it is reconfigured using the LOCATE statement.
On a program termination, all the temporary files containing large data objects are deleted without notice.