How can I solve this warning in iOS? Memory Leak -


this line in function creates warning: performselector may cause memory leak because selector unknown. doing wrong?

- (void)connectiondidfinishloading:(nsurlconnection *)connection {  [_delegate1 performselector:_selector1 withobject:json];  } 

and below method performselector

- (void)httprequest:(nsurl*)url poststring:(nsstring *)poststring method:(int)method withselector:(sel)selector withdelegate:(id)delegate {       _responsedata = [[nsmutabledata alloc] init]; // procedures parse @ desired url request = [nsmutableurlrequest requestwithurl:url                                   cachepolicy:nsurlrequestreloadignoringlocalandremotecachedata                               timeoutinterval:5];  // set http method if (method == 0) {     [request sethttpmethod:@"get"];     // asks xml response     [request setvalue:@"application/json" forhttpheaderfield:@"accept"]; }  _selector1 = selector ; _delegate1 = delegate ;  [self startconnection];  return; } 

you doing nothing wrong.the compiler cause warning because not know selector yet. if there 1 place getting warning use

#pragma clang diagnostic push #pragma clang diagnostic ignored "-warc-performselector-leaks"        [_delegate1 performselector:_selector1 withobject:json]; #pragma clang diagnostic pop 

if there multiple places can define macro

#define suppressperformselectorleakwarning(stuff) \     { \         _pragma("clang diagnostic push") \         _pragma("clang diagnostic ignored \"-warc-performselector-leaks\"") \         stuff; \         _pragma("clang diagnostic pop") \     } while (0) 

and use macro @ places warning caused

suppressperformselectorleakwarning(     [_delegate1 performselector:_selector1 withobject:json]; ); 

call every selector , supress warning


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -