No. If memory pointed by the value of the reference variable using as a parameter of DISPOSE, this either cause run-time error or memory corruption. If parameter points to a memory block that has not been allocated by previous NEW, DISPOSE causes run-time error.
If NewIFormX.getVoziloSteza returns not-NULL reference even if hr is not S_OK_PW, DISPOSE is required.
There is no such rule. For example,
Ref &= V
Ref is not required to be DISPOSEd. Another example:
S &= NEW STRING(100)
Ref1 &= S
Ref2 &= S
Only one variable S, Ref1 or Ref2 must be DISPOSEd in this example because all 3 are pointing to the same memory.
Hmmm. I might state something stupid now but I’ll still give it a try.
So, if some var is referenced to a var which has has been defined (like V LONG) thru compiler, then we don’t need to dispose it because it has a memory block reserved in anycase (which we cannot free at all) as long as the app is running.
But if we create a variable (“NEW it”) at runtime, we therefore reserve some memory block with it and we need to dispose it to free the memory because the app sort of has no idea we made a new variable block somewhere in the memory?
Is that correct? If yes, am I - by calling sz &= NewIFormX… - actually creating some reservation of a memory block and referencing sz to it? So when I dispose(sz), I free that block? And if I dispose(sz) when sz = null, I’m freeing something that does not really exist which is why I could get gpf?
Yes, but if the reference to NEWed data has been assigned to several reference variable, only one of them must be DISPOSEd, If the program is DISPOSEing a QUEUE and its record has fields of a reference type or of ANY type, it can be required to enumerate queue’s record to free referenced data.
You must know better that this function is doing.
If NewIFormX… is allocating a data object, yes, DISPOSE(sz) is required to free it and to invoke that object’s destructor before freeing.
DISPOSE checks that passed reference value is not NULL. If it is NULL, DISPOSE does nothing.