• 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: Does retain not work on ids?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Does retain not work on ids?


  • Subject: Re: Does retain not work on ids?
  • From: Andy Lee <email@hidden>
  • Date: Mon, 23 May 2005 22:01:08 -0400

On May 23, 2005, at 9:40 PM, Ken Tozier wrote:
I have a struct in which one field (type = id) serves as a generic "data" object. In my initialization method, i've tried several different ways to retain the field, but when a later method goes to access it, it's always nil.

Let me see if I understand correctly. You have a C struct (as opposed to a class? And the struct has a member of type "id"? And you assign a non-nil value to that member? And when you check later, the value of the member has become nil?


If this is what you're asking, then it has nothing to do with -retain. Sending -retain to an object does not prevent references to the object from becoming nil. Either something else is clearing the struct member, or you didn't correctly set it in the first place.

By the way, you should be careful where you put the -retain, because it has to be properly balanced by a -release or -autorelease (assuming you eventually do want to dealloc the object). If you make copies of the struct and keep them around, you don't want them to contain references to an object that was dealloc'ed. Unless there's a compelling reason not to (and I can't think of one offhand), you might want to consider using an object rather than a struct.

--Andy

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Does retain not work on ids?
      • From: Ken Tozier <email@hidden>
References: 
 >Does retain not work on ids? (From: Ken Tozier <email@hidden>)

  • Prev by Date: Text Formatting (NSAttributedString?)
  • Next by Date: Re: Text Formatting (NSAttributedString?)
  • Previous by thread: Re: Does retain not work on ids?
  • Next by thread: Re: Does retain not work on ids?
  • Index(es):
    • Date
    • Thread