Re: message to nil? (very basic question)
Re: message to nil? (very basic question)
- Subject: Re: message to nil? (very basic question)
- From: Thomas Lachand-Robert <email@hidden>
- Date: Sat, 19 Jan 2002 23:39:23 +0100
Le samedi 19 janvier 2002, ` 11:24 , Manfred Lippert a icrit :
Hi,
a very basic question from a Cocoa/Obj-C newbie:
Is it allowed to send a message to nil or will it crash or give some
runtime
errors or such things?
It is allowed and just returns 0 or corresponding value of the type (NO
for boolean, nil for pointers, etc.).
It is a major advantage over C++ IMHO.
Example: Do I have to check for nil, if I release an object?:
if (myObject != nil) { // is this necessary?
[myObject release]
}
Not necessary. But in your dealloc methods, it's a good idea to do
[myObject release]; myObject = nil;
since this ensures that you won't release it twice here.
Thomas Lachand-Robert
********************** email@hidden
<< Et le chemin est long du projet ` la chose. >> Molihre, Tartuffe.