Re: Accessor methods and (auto)release: conclusion
Re: Accessor methods and (auto)release: conclusion
- Subject: Re: Accessor methods and (auto)release: conclusion
- From: Marcel Weiher <email@hidden>
- Date: Wed, 7 Aug 2002 00:40:10 +0200
On Wednesday, August 7, 2002, at 12:00 Uhr, Bill Cheeseman wrote:
on 02-08-06 3:57 PM, Ondra Cada at email@hidden wrote:
Particularly, I am afraid the difference between owned (like window
title)
and referenced (like window delegate) object is very important, and
not
stressed out enough in Cocoa (the more so since for both are often
used
the very same operations).
With this distinction on mind, it should be emphasized we are
speaking of
accessors to owned objects here.
This is a helpful distinction to me.
Recently, I was playing with the Cocoa text system and reached the
point
where I had a pointer to my textview's NSTextStorage object. I made a
setter
and getter for my reference to it, but then I thought that my setter
probably shouldn't retain and release per the usual setter pattern
because I
don't own the NSTextStorage -- I just have a reference or pointer to
it, for
my convenience.
It probably should, unless there is a good reason against it.
The text system documentation says that when I release an NSTextStorage
object, the text system will release its NSLayoutManagers and
NSTextContainers and I think its NSTextViews.
The documentation is obviously a bit lax at this point. It should say
"when a NSTextStorage gets deallocated". I haven't actually tried
this, but it would be bizarre for the text-system to do this on a
"release".
So I suppose I can't retain and release without disrupting my text
system.
Yes you can. It will only be disrupted when the last retain is
released.
After releasing it, I suppose
I would have to build the whole system back up again properly.
Luckily, no.
I give this as an example of the confusion that accessor theory and
memory
management can bring to a relative beginner.
Well, this one was probably caused by inaccurate documentation, but I
do think there is a point for making this as conceptually simple as
possible, and as Georg pointed out, it really *is* very simple unless
you get bitten by inaccurate documentation or inapropriate magic.
What is the answer for
NSTextStorage? When I'm just pointing to it, I shouldn't retain and
release
in a convenience setter, is this right?
Yes, unless you are already being retained by the NSTextStorage, which
seems unlikely.
Marcel
--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.