• 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
Use of weak reference in non-circular reference situation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Use of weak reference in non-circular reference situation


  • Subject: Use of weak reference in non-circular reference situation
  • From: Eric <email@hidden>
  • Date: Wed, 31 May 2006 03:14:40 -0700

Is it considered good Cocoa style, in the case where a single object has two
references (direct or indirect) to a particular object, to use weak
reference for one of the references?  For example:

Object A has an array "aArray" of objects and an instance variable "aObject"
that points to one particular object in the array.   Since aArray is not
deallocated until Object A is deallocated, the object (in the array)
referenced by aObject will always be in memory and therefore aObject is a
weak reference to the object it points to in aArray.  Convenience (of not
having to retain and release aObject) is the only reason for this.

Since IBOutlet is apparently such a weak reference, is this a recommended
way of doing things?  Or is it recommended to always retain an object as
long as there is a reference to it even when it's safe to assume the object
will always be there, as in the above senario?

An additional example would be:

A window controller has instance variables holding different NSFont objects
to use in the document, one instance variable for each font.  Each instance
variable is retained as usual.  There is a separate instance variable
"currentFont" that points to the currently active font.  In this case,
should I retain the currentFont?  Or just assume it will be retained by the
other instance variables?

Thanks,
Eric
_______________________________________________
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: Use of weak reference in non-circular reference situation
      • From: James Bucanek <email@hidden>
    • Re: Use of weak reference in non-circular reference situation
      • From: "John C. Randolph" <email@hidden>
  • Prev by Date: RE: Exposing Methods in a Framework
  • Next by Date: Re: Client ssh
  • Previous by thread: Re: Client ssh
  • Next by thread: Re: Use of weak reference in non-circular reference situation
  • Index(es):
    • Date
    • Thread