On May 7, 2010, at 9:27 PM, Roland King <r...@rols.org> 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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com