1
\$\begingroup\$

I have some doubt about how NSString is released in ARC Mode.

I would like to know if have something i can do to release a nsstring when i want in arc mode.

Take a look at this code:

__block NSString *strImage = nil;
 dispatch_sync(backGround, ^{
 // Convert NSData To NSString.
 strImage = [UIImagePNGRepresentation([UIImage imageWithData:reg.photoData]) base64Encoding];
 });
 // Prepare Request Operation.
 NSString * strPost = @"myUrl";
 strPost = [strPost stringByAppendingFormat:@"}&image="];
 strPost = [strPost stringByAppendingFormat:@"%@",strImage];
 //NSLog(@"POST: %@",strPost);
 // setting up the URL to post to
 NSString *urlString = @"myURLAPI";
 // setting up the request object now
 NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
 [request setURL:[NSURL URLWithString:urlString]];
 [request setHTTPMethod:@"POST"];
 /*
 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 *contentType = [NSString stringWithFormat:@"application/x-www-form-urlencoded"];
 [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
 /*
 now lets create the body of the post
 */
 NSMutableData *body = [NSMutableData data];
 [body appendData:[NSData dataWithData:[strPost dataUsingEncoding:NSUTF8StringEncoding]]];
 // setting the body of the post to the reqeust
 [request setHTTPBody:body];
 AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
 //MY DOUBT ABOUT RELEASE THIS STR
 @autoreleasepool {
 strImage = nil;
 }

is it correct or have a best way to do it? Thank you

asked Aug 27, 2013 at 14:59
\$\endgroup\$
0

1 Answer 1

1
\$\begingroup\$

Also @autoreleasepool does not look are the objects create outside of it scope, just the object used within. Also if using are there is not need for the @autoreleasepool at all, since the scope variables will be released and nilled at the end of the scope.

answered Aug 30, 2013 at 13:30
\$\endgroup\$
1
  • \$\begingroup\$ so when my function end the str compiler knows that this str need to release? dont i need the autorelease? \$\endgroup\$ Commented Aug 30, 2013 at 21:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.