0

HTTP 요청으로 이미지를 게시하려고하면 내 앱이 충돌합니다. 이미지를 서버에 업로드하려고합니다. 크래시가 [pool release] 메시지에 갇히므로 내 자동 실행 풀과 관련된 충돌이 표시됩니다.iPhone : 맞춤 자동 복구 풀에서 충돌이 발생했습니다.

#0 0x326712f8 in prepareForMethodLookup() 
#1 0x3266cf5c in lookUpMethod() 
#2 0x32668f28 in objc_msgSend_uncached() 
#3 0x33f70996 in NSPopAutoreleasePool() 
#4 0x33f82a6c in -[NSAutoreleasePool drain]() 
#5 0x00003d3e in -[CameraViewcontroller save:] (self=0x811400, _cmd=0x319c00d4, number=0x11e210) at /Users/hardikrathore/Desktop/LiveVideoRecording/Classes/CameraViewcontroller.m:266 
#6 0x33f36f8a in __NSFireDelayedPerform() 
#7 0x32da44c2 in CFRunLoopRunSpecific() 
#8 0x32da3c1e in CFRunLoopRunInMode() 
#9 0x31bb9374 in GSEventRunModal() 
#10 0x30bf3c30 in -[UIApplication _run]() 
#11 0x30bf2230 in UIApplicationMain() 
#12 0x00002650 in main (argc=1, argv=0x2ffff474) at /Users/hardikrathore/Desktop/LiveVideoRecording/main.m:14 

충돌 보고서는 다음 코드의 마지막 줄은 충돌 지점이라고 말한다 : 여기

은 충돌 보고서입니다. (라인 번호 266)

-(void)save:(id)number 
{ 
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
    j =[number intValue]; 
    while(screens[j] != NULL){ 
     NSLog(@" image made : %d",j); 
     UIImage * image = [UIImage imageWithCGImage:screens[j]]; 
     image=[self imageByCropping:image toRect:CGRectMake(0, 0, 320, 240)]; 
     NSData *imgdata = UIImageJPEGRepresentation(image,0.3); 
     [image release]; 

     CGImageRelease(screens[j]); 
     screens[j] = NULL; 

     UIImage * image1 = [UIImage imageWithCGImage:screens[j+1]]; 
     image1=[self imageByCropping:image1 toRect:CGRectMake(0, 0, 320, 240)]; 
     NSData *imgdata1 = UIImageJPEGRepresentation(image1,0.3); 
     [image1 release]; 

     CGImageRelease(screens[j+1]); 
     screens[j+1] = NULL; 
     NSString *[email protected]"http://www.test.itmate4.com/iPhoneToServerTwice.php"; 
     // setting up the request object now 
     NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init]; 
     [request setURL:[NSURL URLWithString:urlString]]; 
     [request setHTTPMethod:@"POST"]; 

     NSString *fileName=[VideoID stringByAppendingString:@"_"]; 
     fileName=[fileName stringByAppendingString:[NSString stringWithFormat:@"%d",k]]; 
     NSString *fileName2=[VideoID stringByAppendingString:@"_"]; 

     fileName2=[fileName2 stringByAppendingString:[NSString stringWithFormat:@"%d",k+1]]; 
     /* 
     add some header info now 
     we always need a boundary when we post a file 
     also we need to set the content type 

     You might want to generate a random boundary.. this is just the same 
     as my output from wireshark on a valid html post 
     */ 
     NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"]; 
     NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary]; 
     [request addValue:contentType forHTTPHeaderField: @"Content-Type"]; 

     /* 
     now lets create the body of the post 
     */ 
     //NSString *count=[NSString stringWithFormat:@"%d",front];; 
     NSMutableData *body = [NSMutableData data]; 
     [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];  
     //[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; count=\"@\"";filename=\"%@.jpg\"\r\n",count,fileName] dataUsingEncoding:NSUTF8StringEncoding]]; 
     [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@.jpg\"\r\n",fileName] dataUsingEncoding:NSUTF8StringEncoding]]; 
     [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; 
     [body appendData:[NSData dataWithData:imgdata]]; 
     [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 
     //second boundary 

     NSString *string1 = [[NSString alloc] initWithFormat:@"\r\n--%@\r\n",boundary]; 
     NSString *string2 =[[NSString alloc] initWithFormat:@"Content-Disposition: form-data; name=\"userfile2\"; filename=\"%@.jpg\"\r\n",fileName2]; 
     NSString *string3 =[[NSString alloc] initWithFormat:@"\r\n--%@--\r\n",boundary]; 


     [body appendData:[string1 dataUsingEncoding:NSUTF8StringEncoding]]; 
     [body appendData:[string2 dataUsingEncoding:NSUTF8StringEncoding]]; 
     //experiment 
     //[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile2\"; filename=\"%@.jpg\"\r\n",fileName2] dataUsingEncoding:NSUTF8StringEncoding]]; 
     [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; 
     [body appendData:[NSData dataWithData:imgdata1]]; 
     //[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 
     [body appendData:[string3 dataUsingEncoding:NSUTF8StringEncoding]]; 
     // setting the body of the post to the reqeust 
     [request setHTTPBody:body]; 
     // now lets make the connection to the web 
     NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 
     NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; 
     if([returnString isEqualToString:@"SUCCESS"]) 
     { 
      NSLog(returnString); 
      k=k+2; 
      j=j+2; 
      [self performSelectorInBackground:@selector(save:) withObject:(id)[NSNumber numberWithInt:j]]; 
     } 

     [imgdata release]; 
     [imgdata1 release]; 

    [NSThread sleepForTimeInterval:.01]; 

    } 
    [pool drain];   //<-------------Line 266 
} 

나는 크래시의 원인을 이해하지 못한다.

+1

옆에있는 체크 표시를 눌러 대답을 수락해야합니다. 한달 동안 8 가지 질문을하고 아무 것도 받아들이지 않았습니다. 따라서 사람들이 문제를 파악하는 데 시간을 할애하지 않아서 stackoverflow 시스템이 혼란 스럽습니다. – TechZen

+0

15 분 동안 편집 한 후에는 닫지 마십시오. – TechZen

답변

1

사용자 정의 자동 풀 풀이 필요하지 않습니다. 한 번에 수십 개의 이미지를 저장하지 않으면 (있을 법하지 않음) 로컬 풀이 필요하지 않습니다.

어쨌든 루프가 전체 메소드를 포함하기 때문에 루프 외부에 자동 해제 풀을 만드는 것은 그리 중요하지 않습니다. 사용자 정의 풀이 필요하다면 루프 내부에 넣어야 루프를 통과 할 때마다 메모리가 정리됩니다.

크래시는 풀과 직접 관련이 없지만 간단히 디버거가 트래핑하는 곳입니다. 디버깅을 시작하려면 autorelease 풀과 해당 드레인을 주석으로 처리하십시오. 아마 충돌의 원인을 밝혀 낼 것입니다.

좋은 경험 법칙. 코드 세그먼트를 테스트하고 필요하다고 판단 할 때까지 로컬 풀을 만들지 마십시오. 드물게 필요한 개체는 하나 뿐이며 작은 범위에 많은 수의 개체를 만들 때만 필요합니다.

0

크래시 보고서에 따르면 충돌이 발생한 이유를 찾기가 어렵습니다. NSLog를 사용하여 디버그 정보를 얻을 수 있는지 확실하지 않은 경우 (적어도 예제 코드에는 포함되지 않음)? NSLog는 출력 콘솔에 메시지를 출력하는 기능입니다. 충돌이 발생한 곳을 찾아내는 훌륭한 도구입니다.

관련 문제