Use of weak reference in non-circular reference situation
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