Re: Calling -retain inside -dealloc
Re: Calling -retain inside -dealloc
- Subject: Re: Calling -retain inside -dealloc
- From: j o a r <email@hidden>
- Date: Mon, 27 Jun 2005 10:51:53 +0200
On 27 jun 2005, at 08.48, Andrew Garber wrote:
What if I subclassed NSMutableArray so that adding or removing objects
would affect the retain count of the objects?
Ehrm... It already does!
Or how about adding a category to NSMutableArray which contains two
methods: -addObjectWithoutRetaining and -removeObjectWithoutReleasing?
I usually use CFMutableArray for that purpose. If you configure it to
not have retain / release callback functions, it will work that way
out of the box. Simple and easy.
On 27 jun 2005, at 09.15, Andrew Garber wrote:
The problem isn't that my class is suffering performance-wise. This is
just an experiment to see how much of a performance increase can be
gained in this case by using an alternative to NSNotifications.
Keeping references to instances in various class variables (like an
NSMutableArray) was the most elegant approach I could think of.
NSMutableArray's addObject, removeObject, and containsObject methods
are very convenient for what I'm trying to accomplish, so I would be
great I could use an NSMutableArray without having it mess with the
retain/release counts.
That is still not an explanation why you would have to override
standard memory management in this case.
In my opinion, you shouldn't overload retain+release+dealloc to do
anything but simple instance memory management. If you do, you very
easily get into trouble later on. I'm not saying that it can't be
done, just that you often don't foresee the type of side effects it
will have.
If you're going to store your object instances in an container that
doesn't retain / release your objects you're going to have to make
sure that they are removed from that container when they're
deallocated in any case - so there is no difference between having to
do that, and just using a regular container and removing the
instances when they're supposed to go away.
You will in either case not escape the responsibility of having to
ensure that the instances are removed before being deallocated, but I
think it's cleaner to not place that logic in the memory management
machinery.
j o a r
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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