by Ursego » 16 Apr 2013, 11:50
The function uf_destroy() is extremely simple - it just DESTROYs the object, sent to it - nothing else! But it is not as useless as you think - it allows to POST object's destroying. Use this function if you have an object, created locally in a function, and many RETURNs from that function. Call uf_destroy() with POST, and only once - just after you CREATE the object. This approach exempts you from writing DESTROY many times, before each RETURN. In the next example (treating a local DataStore), instead of
- Code: Select all
lds = create lds
[fragment 1]
if ... then
destroy lds
return
end if
[fragment 2]
if ... then
destroy lds
return
end if
destroy lds
you will write this way:
- Code: Select all
lds = create lds
gn_util.post uf_destroy(lds)
[fragment 1]
if ... then return
[fragment 2]
if ... then return
So, here is the code of uf_destroy() (it can be added to the utilities NVO of your application or wherever):
- Code: Select all
/**********************************************************************************************************************
Dscr: Enables to POST object's destroying. Example of use: http://code.intfast.ca/viewtopic.php?f=4&t=90
***********************************************************************************************************************
Arg: apo (PowerObject)
***********************************************************************************************************************
Developer: Michael Zuskin - http://linkedin.com/in/zuskin | http://code.intfast.ca/
**********************************************************************************************************************/
if not IsValid(apo) then
return
end if
destroy apo
return
BTW...
In fact, in our days, there is no need to destroy previously created objects - the garbage collector will clean the memory for you. GC is a great invention! Now we are not afraid of visitation of God if we disobey the rule "destroy in the same script where created" - we simply don't think about destroys at all, concentrating on more important stuff. We can pass the created object to another function (even POSTed!) or object (for example, using OpenWithParm()) and forget about memory management!