Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 854843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:59:23+00:00 2026-05-15T07:59:23+00:00

My app is crashing when I try to post images in an HTTP request.

  • 0

My app is crashing when I try to post images in an HTTP request. I am trying to upload images to a server. The crash appears related to my autorelease pool because the crash is trapped at the [pool release] message.

Here is the crash report:

#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

The crash report says that final line of the following code is the point of the crash. (Line No. 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 *urlString=@"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
}

I don’t understand what is causing the crash.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:59:23+00:00Added an answer on May 15, 2026 at 7:59 am

    You don’t need a custom autorelease pool here. Unless you are saving dozens of images at a time (unlikely) a local pool is unnecessary.

    There is not much point creating an autorelease pool outside the loop since the loop encompasses the entire method anyway. If you did need a custom pool, you should put it inside the loop so that it cleans up the memory for each pass through the loop.

    The crash may have nothing directly to do with the pool but that is simply where the debugger traps it. To start debugging, comment out the autorelease pool and its drain. That will probably uncover the source of the crash.

    As a good rule of thumb. Don’t create a local pool until you’ve test the code segment and determined it needs one. Only rarely is one needed and then only when you create large numbers of objects in a small scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When trying to show the UIImagePickerController I had strange problems with my app crashing
My app worked ok on iPhone SDK 3.1. However, when I try to run
If one of your beta testers has problems with your app crashing, how do
My app is crashing when testing on the device, but not on the simulator.
My app has many controls on its surface, and more are added dynamically at
An app I'm writing always crashes on a clients computer, but I don't get
My app is installed via NSIS. I want the installer to install the program
My app uses a WebRequest at certain points to get pages from itself. This
My app keeps track of the state of about 1000 objects. Those objects are
Our app (already deployed) is using an Access/Jet database. The upcoming version of our

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.