Re: An object should not retain its delegate, but what about its data source ?
Re: An object should not retain its delegate, but what about its data source ?
- Subject: Re: An object should not retain its delegate, but what about its data source ?
- From: Alastair Houghton <email@hidden>
- Date: Wed, 1 Aug 2007 12:10:40 +0100
On 31 Jul 2007, at 22:27, Erik Buck wrote:
An object should not retain its delegate.
Should an object retain its data source ?
I never thought it did or should, and in some custom objects where
I've given them a data source, I've never been inclined to retain it,
for the same reason that the delegate usually isn't retained---it
would often create a retain cycle.
Do NSBrowser and NSTableView retain their data sources ?
As Nick Zitzmann pointed out, NSBrowser has no data source.
NSTableView definitely does not retain its data source though (I
checked):
NSLog (@"My retain count is %d", [self retainCount]);
[tableView setDataSource:self];
[tableView reloadData];
NSLog (@"My new retain count is %d", [self retainCount]);
results in:
2007-08-01 12:01:55.476 DataSourceTest[709] My retain count is 1
2007-08-01 12:01:55.476 DataSourceTest[709] My new retain count is 1
My thinking right now is that a delegate is not essential so the
object that has a delegate doesn't "own" the delegate. However, a
data source may be essential in which case the object with a data
source does "own" the data source and should retain it.
I can see the reasoning, however I think there would be a very real
risk of retain cycles if objects were to retain their data sources.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
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