dispose: bug or feature?

Peter N Lewis peter at stairways.com.au
Tue Dec 11 03:48:01 CET 2007


At 9:44 -0800 10/12/07, Scott Moore wrote:
>John L. Ries wrote:
>
>>There probably wouldn't be anything wrong with GPC automatically 
>>setting pointers to nil when disposing them, but that would be 
>>non-standard and I suspect that most people (myself included) would 
>>do it themselves anyway (for portability's sake) unless the pointer 
>>was going to be immediately reassigned.
>>
>
>No, that's perfectly ok with the standard. It simply specifies that the
>value is undefined, which means set to nil is as good as anything else.

I do not believe that is correct.

I'm pretty sure the semantics for dispose are that it takes a value 
parameter, and so has no ability to modify the pointer.

As much as I might prefer the definition to be that the pointer is 
set to nil, and like Adriaan, my preference is for wrapper functions 
that are nil-safe and idempotent, changing the behaviour of dispose 
could make correct code fail.

For example, imagine this pseudocode:

p = New pointer.
AddToListOfPointers( list, p );
Dispose( p );
RemoveFromListOfPoitners( list, p );

That is perfectly legal code, but would fail if dispose became a by 
reference, set to nil procedure.

As Adriaan described, if you want that facility, simply write your 
own wrappers.

My own wrappers included:

* nil-safe
* nil-setting
* leak checking code
* memory trashing

Enjoy,
    Peter.

-- 
Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
<http://www.stairways.com/>           <http://download.stairways.com/>





More information about the Gpc mailing list