Re: Cocoa-dev Digest, Vol 5, Issue 600
Re: Cocoa-dev Digest, Vol 5, Issue 600
- Subject: Re: Cocoa-dev Digest, Vol 5, Issue 600
- From: Greg Titus <email@hidden>
- Date: Sun, 13 Apr 2008 13:06:32 -0700
On Apr 13, 2008, at 12:40 PM, Alex Curylo wrote:
No, I can personally assure you that exact practice has led me to
finding many dozens -- quite possibly several hundreds by now
actually -- of 'calling methods of a deleted object' type bugs in C+
+ code, particularly game code I port from Windows, which somehow
always seems to have been written by semi-literate chimpanzees on
crack. And perhaps I am unfair to the chimpanzees here.
As a former game porter, let me offer my condolences here. I know
exactly what you mean.
It does seem that class of problem is much less likely to arise with
Objective-C object references (I'm still fairly new to this Cocoa
thing) but as long as I still work with any C++ objects or raw
pointers, I'm going to consider that "set things up so anything
accessing this object's memory after I'm done with it promptly
causes an access violation" is a valuable habit -- nay, essential
practice -- in properly defensive programming. Autoptrs and the like
help, but they're not foolproof. Stands to reason that the retain/
[auto]release paradigm isn't completely foolproof either, although
it does seem pretty resistant to commonly accepted levels of foolery
so far.
The big difference is that in Objective-C, trying to send a message to
nil results in a no-op instead of an access violation, so your
defensive C++ practice is actually going to tend to mask those same
errors in Objective-C and make them harder to track down.
Hope this helps,
- Greg
_______________________________________________
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