KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Clearing a local BLOB variable
PRODUCT: 4D | VERSION: 6.5 | PLATFORM: Mac & Win
Published On: October 13, 2000

If you're storing a BLOB in a local variable, is it necessary to clear it before you exit the method, to avoid tying up memory?
The answer is that just like any other local variable, the BLOB will be cleared when the method finishes executing. So it is not necessary to explicitly clear the BLOB with a line of code like:


SET BLOB SIZE($MyBLOBVariable;0)

But there is a reason why you might want to make a regular practice of doing that anyway. Consider two facts about the 4D programming language:

1. You cannot create a pointer to a local variable.
2. You cannot return a BLOB as a function result.

Particularly due to the limitation that you can't return a BLOB as a function result (in the $0 parameter), there's an increased possibility that you might later change the scope of the BLOB variable from a local variable to a process variable.
It's possible that sometime later when you refine the method containing this local BLOB variable, you might insert into its code a call to a second method that modifies the BLOB. In order to do this, you'll need to change the BLOB from a local variable to a process variable, so that you can create a pointer to the BLOB variable. Then you can pass the pointer to the second method, so that code can read and write to the BLOB variable:


ModifyBLOB (MyBLOBVariable->)

If you get preoccupied with writing the code for the second method, you might forget that since the BLOB in the first method is now a process variable, it needs to be cleared before you exit that method. But if you had previously used the SET BLOB SIZE command to clear the BLOB when it was a local variable, you'll be covered when you rename the BLOB to make it a process variable.