Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

carlosbutler

macrumors 6502a
Original poster
Feb 24, 2008
691
2
I have been looking around on the apple developer and this site (i guess not long enough since i can not find the answer) for my question.

When releasing an object:
Code:
UILabel *label = [[UILabel alloc] init];
[label release];

Is it possible to release multiple objects in one go, by doing:
Code:
[obj1, obj2, obj3 release]

I have tried this, and there is no compile, so obviously syntactically it is fine. But I am not sure if it is doing anything. Any suggestions?
 
Last edited:

admanimal

macrumors 68040
Apr 22, 2005
3,531
2
It is not possible to send a message (e.g. release) to multiple objects in this way. I'm pretty sure that all your code does is send release to obj3 because the comma (i.e. expression separator) operator evaluates to whatever is on its right side. It is a legal expression, but does nothing like what you think it does.
 
Last edited:

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
You could do something like this:

Code:
[[NSArray arrayWithObjects:obj1, obj2, obj3,nil] makeObjectsPerformSelector:@selector(release)];

Note that this is much lower performances than calling release 3 times: you have to create a new NSArray object and then internally NSArray will iterate over it's contents.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.