Re: self = [super init], nil?
Re: self = [super init], nil?
- Subject: Re: self = [super init], nil?
- From: Kyle Sluder <email@hidden>
- Date: Fri, 7 May 2010 23:21:49 -0700
On May 7, 2010, at 9:27 PM, Roland King <email@hidden> wrote:
If you're out of memory then it would be alloc returning nil, not
init. In that case init wouldn't be called at all. The OP's question
was about whether you need to check [ super init ] for nil in your
subclass init method, if you get to that point then alloc did manage
to allocate an object for you.
You are correct that I was thinking of +alloc first and foremost, but
it's theoretically possible to get past +alloc, run out of memory, and
fail in -init. (As bbum said, maybe not in the current implementation,
but certainly not set in stone.)
Whether you want to also check for the case your entire [ [ MyObject
alloc ] init ] returns nil, which it would if allocation failed or
if initialization failed is another question, I rarely do unless nil
is an anticipated return which means something for that class.
I would be very concerned with NULL pointer dereferences. These kinds
of events are just the thing attackers look to exploit.
--Kyle Sluder
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden