• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Cocoa-dev Digest, Vol 5, Issue 600
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa-dev Digest, Vol 5, Issue 600


  • Subject: Re: Cocoa-dev Digest, Vol 5, Issue 600
  • From: Alex Curylo <email@hidden>
  • Date: Sun, 13 Apr 2008 12:40:35 -0700


On 13-Apr-08, at 12:02 PM, email@hidden wrote:
why is it necessary to set the variable appointments (for instance) to nil
in this example? Should we do this for each variable? When have we to do
this?

IMO, it's totally unnecessary. Seems to be a cargo culting thing more than anything else.


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.

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.

--
Alex Curylo -- email@hidden -- http://www.alexcurylo.com/

There are two great secrets to success in life.
The first is to not tell everything you know.

_______________________________________________

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


  • Follow-Ups:
    • Re: Cocoa-dev Digest, Vol 5, Issue 600
      • From: Greg Titus <email@hidden>
  • Prev by Date: Re: Why should we set ivars to nil in dealloc?
  • Next by Date: Re: Why should we set ivars to nil in dealloc?
  • Previous by thread: Re: Subclassing NSScroller
  • Next by thread: Re: Cocoa-dev Digest, Vol 5, Issue 600
  • Index(es):
    • Date
    • Thread