0

I am using swrevealviewController for sliding from one view to another. But My app is crashing randomly , When I sliding from one view to another , On every view , There is server call for showing video list.

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{

    //NSLog(@"connection did finish loading %@",responseData);
    //NSString *str = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];
    //NSLog(@"tdshjfhdkh %@",str);

    [self.resopnseDelagate carryData:responseData];
    responseData = nil;
}

My app is crash in above method randomly and give an error in log as given bellow :: [viewController retain]:message sent to deallocated instance 0xa081994e

I am also to debug this issue by using Crashlytic ,But unable to understand their log as given below :

Thread : Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x3a78152c objc_retain + 11
1  DemoApp                       0x000d2c81 -[Connection connectionDidFinishLoading:] (Connection.m:76)
2  Foundation                     0x3341a6fd __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke_0 + 16
3  Foundation                     0x3335a1f9 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 200
4  Foundation                     0x3335a115 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 60
5  CFNetwork                      0x327bc45f ___delegate_didFinishLoading_block_invoke_0 + 26
6  CFNetwork                      0x327bbb43 ___withDelegateAsync_block_invoke_0 + 54
7  CFNetwork                      0x327e3fcb ___performAsync_block_invoke_068 + 18
8  CoreFoundation                 0x32a2574d CFArrayApplyFunction + 176
9  CFNetwork                      0x327e442b RunloopBlockContext::perform() + 74
10 CFNetwork                      0x3274803d MultiplexerSource::perform() + 188
11 CoreFoundation                 0x32ab4683 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
12 CoreFoundation                 0x32ab3ee9 __CFRunLoopDoSources0 + 212
13 CoreFoundation                 0x32ab2cb7 __CFRunLoopRun + 646
14 CoreFoundation                 0x32a25ebd CFRunLoopRunSpecific + 356
15 CoreFoundation                 0x32a25d49 CFRunLoopRunInMode + 104
16 GraphicsServices               0x365e92eb GSEventRunModal + 74
17 UIKit                          0x3493b301 UIApplicationMain + 1120
18 DemoApp 

                  0x000da839 main (main.m:16)

Please Help me ,Thanks in Advance.

KDRocks
  • 161
  • 3
  • 18
  • are you using ARC or manual memory management? – Daij-Djan Mar 31 '14 at 08:45
  • Clear Derived data, then quite simulator. – Vineesh TP Mar 31 '14 at 08:47
  • I am using ARC on Xcode 5.02 – KDRocks Mar 31 '14 at 09:12
  • @KDRocks Can you write code which is responsible for calling `connectionDidFinishLoading` ? – Rahul Patel Mar 31 '14 at 11:44
  • This is automatically called when I request to server using nsurlconnection NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0f]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"]; [request setHTTPMethod:@"POST"]; NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:YES]; [connection start]; – KDRocks Mar 31 '14 at 11:58

2 Answers2

0

You are trying to use a view controller that no longer exists in memory so firstly turn on NSZombies to find out where this is happening How to enable NSZombie in Xcode?

Secondly before calling your delegate you should check to ensure its not nil

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{

    //NSLog(@"connection did finish loading %@",responseData);
    //NSString *str = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];
    //NSLog(@"tdshjfhdkh %@",str);

    if([self.responseDelagate respondsToSelector:@selector(carryData:)]) {
        [self.resopnseDelagate carryData:responseData];
    }
    responseData = nil;
}
Community
  • 1
  • 1
Flexicoder
  • 8,251
  • 4
  • 42
  • 56
  • you are partly right. he is using something thats no longer there - alas messages to nil are totally fine and woundt crash here. the problem likely is that it isnt there but the pointer isnt nil. – Daij-Djan Mar 31 '14 at 08:45
  • If the delegate method is not marked @optional the only use of the if condition is to hide bugs -> don't do it. – Matthias Bauch Mar 31 '14 at 08:46
  • carryData is a delegate method , which is used to passed received data to any view controller.and used as in connection.h class @property(assign,nonatomic)id resopnseDelagate; – KDRocks Mar 31 '14 at 09:14
  • [viewController retain]:message sent to deallocated instance 0xa081994e comes after nszombie enabled – KDRocks Mar 31 '14 at 09:30
0

try releasing responseData in dealloc like this

-(void)dealloc{

 [repsonseData release];
 responseData = nil;

}

and also check whether you are setting the responseDelegate before calling a method on it

hariszaman
  • 8,202
  • 2
  • 40
  • 59
  • I am still getting crash, my problem seem like this link image http://answer.techwikihow.com/554857/corefoundation-trap-error-tread1exc_breakpoint-codeexc_arm_breakpoint-subcode0xdefe.html , Please help me. – KDRocks Mar 31 '14 at 11:08