Re: Retain/release objects in an array...
Re: Retain/release objects in an array...
- Subject: Re: Retain/release objects in an array...
- From: Ondra Cada <email@hidden>
- Date: Wed, 24 Jul 2002 14:41:16 +0200
On Wednesday, July 24, 2002, at 07:27 , Jiva DeVoe wrote:
I'm unclear... If I return an objectEnumerator from an array in one of my
functions... Should I autorelease it before returning it?
Nope. It is autoreleased already. Contrariwise, you need to retain it in
(somewhat rare) case you want to keep using it over more eventloop cycles
(in which case it would keep its array there too -- you don't need to
retain it explicitly, which you would have to should objectAtIndex: be
used instead).
And should I
retain it on the other end?
Sorry, but this is unclear to me. What "other end"? If you retained it
(see above), you've to (auto)release it when you are through with it.
Does an objectEnumerator count as an object?
It is a very standard object, of course.
Also, if I get an object via objectAtIndex, should I retain that as well?
Again, use the generic retain/release rules.
Of course, if you know that the array does not change nor release, you can
do without (since all the objects inside would live as long as the array),
but that's a generally bad proramming practice, which would decrease
readability, maintainability, and robustness of your code. That said, it
is in some cases still a proper code, but be sure that you considered the
potential problems, and comment on, like
...
o=[a objectAtIndex:i]; // no need to retain, array kept forever
...
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc
_______________________________________________
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.