The DelVar command deletes the contents of a variable (and thus the variable itself) from memory. You can use the DelVar command with any variable: reals, lists, matrices, strings, pictures, etc. However, you cannot use DelVar on specific elements of a matrix or string; it will actually throw a ERR:SYNTAX error. (It also does not work on programs, unfortunately.)
If the DelVar command is used with a real variable, the variable is not only deleted from memory but automatically set to zero the next time it is used. This is equivalent to using store (→) to manually set the variable yourself. Because the DelVar command is two bytes instead of one, there is no size difference between the two.
:0→A same as :DelVar A
While there is no size difference between the two, DelVar does have some problems that go along with using it. If used in a For loop to delete the counter variable or used to delete the variable and/or value in the IS>( or DS<( commands before using them, it will cause an ERR:UNDEFINED error.
This is a result of the way that the interpreter in TI-Basic is designed, so there is nothing you can do about it. You just need to be cognizant of it when using DelVar in a For loop or together with IS>( or DS<(.
When you are done using variables, you should delete them at the end of the program with the DelVar command to cleanup. Each variable takes up a set amount of space (for example, a real variable is 15 bytes), and the more variables you can delete the more free memory is available. Free memory helps your programs run faster and allows you to pack more things on your calculator.
Because the DelVar command doesn't update the Ans variable, you can use DelVar and the current value in Ans will still be preserved for later use.
The DelVar command does not need a line break or colon (which indicates a new line of code) following the variable name. This allows you to make chains of variables (organized in whatever order you want), and it saves a byte for each line break or colon removed.
:DelVar A :DelVar B can be :DelVar ADelVar B
Besides making chains of variables, the DelVar command also allows you to take the command from the next line and put it immediately after the DelVar command.
:DelVar A :Disp "Hello can be :DelVar ADisp "Hello
There are, however, two cases in which the following statement will be ignored, so you should add a newline:
The speed of the DelVar command depends on the circumstance where it is used. When the variable already exists, DelVar is slower because it has to deallocate the variable from the RAM . DelVar is also significantly slower for zeroing real variables when compared to using store to set the variable to 0. The speed difference becomes apparent when the value is reset many times, but is not a major factor if only used sparingly.
- ERR:SYNTAX is thrown when trying to delete a system variable (e.g. DelVar Xmin) or a program, even though this is syntactically correct.
- ERR:UNDEFINED is thrown if you delete the loop variable while inside the loop, or delete the variable used in IS>( or DS<(.
- ERR:ARCHIVED is thrown if you use DelVar on an archived variable.