On 18 Oct 2011, at 00:05, David Duncan wrote:

> On Oct 15, 2011, at 11:58 PM, Gerriet M. Denkmann wrote:
> 
>> I have this code:
>>              
>> for( id aThing in someArray )
>> {
>>      if ( [ aThing respondsToSelector: @selector(setTitle:) ] )
>>      {
>>              [ self  replaceIn:              aThing 
>>                              readSelector:   @selector(title) 
>>                              writeSelector:  @selector(setTitle:) 
>>                              withTable:              tableName 
>>              ];
>>      }
>> }
>> 
>> 
>> - (void)replaceIn: thing  readSelector: (SEL)selectorIn  writeSelector: 
>> (SEL)selectorOut  withTable: (NSString *)tableName;
>> {
>>      NSString *key = [ thing performSelector: selectorIn ];
>>      ...
>>      NSString *rep = ...
>>      [ thing performSelector: selectorOut withObject: rep ];
>> }
>> 
>> Now, using Arc I am told that  "PerformSelector may cause a leak because its 
>> selector is unknown".
>> What I am supposed to do about this? I really want to have code without 
>> warnings.
> 
> 
> ARC can't see the selector you pass to know if it conforms to the memory 
> management policy implied by the -performSelector* calls, hence it reports 
> this warning. If you called [thing performSelector:@selector(copy)] for 
> example, you would leak. If you called [thing 
> performSelector:@selector(release)] (not valid in ARC, but possibly if the 
> selector is passed back by other means) you would over-release and crash.

I understand this. So I tried to tell the compiler that the passed selector is 
not like copy:

- (void)replaceIn: thing  readSelector: 
(__attribute__((ns_returns_not_retained)) SEL)selectorIn 
{
        NSString *key = [ thing performSelector: selectorIn ]; 
}

But it still complains:  "PerformSelector may cause a leak because its selector 
is unknown".
Sure, it is unknown, but it's non-retaining behaviour is known.

Is this a bug?

I will have to think about the block approach. But not now — it is past 
midnight already.

Kind regards,

Gerriet.

_______________________________________________

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