> #define autoscoped __attribute__((cleanup(releaseObject)))

> static inline
> void releaseObject(id *object) {
>    [*object release];
> }

> - (void) demo {
> autoscoped NSArray *myArray = [[NSArray alloc] init];
> //do some stuff
> }

> The autoscoped macro tags the lval with an attribute that causes the
> cleanup function to be called when the lvals scope disappears.

> It is not quite the same as a smart pointer, but it does allow me to
> have objects automatically released when their scope disappears,
> without causing autorelease traffic.


That's very interesting, I didn't know that attribute existed.  I imagine 
that post-dates autorelease pools by some years.  But most objects returned 
by framework functions are autoreleased which means you can only get rid of 
them by bracketing them with an autorelease pool. This bugs me somewhat and 
is obviously less efficient than just throwing them away when you are done 
with them.  But it does let you pass @"string" as a function parameter I 
suppose without having to release it afterwards.  Still can't say I like it 
much.  Sorry if I hijacked the thread.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to