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

  • SEARCH
  • Home
  • 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 7066755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:07:08+00:00 2026-05-28T05:07:08+00:00

Very similar to this question , I am trying to convert a project that

  • 0

Very similar to this question, I am trying to convert a project that uses ASIHTTPRequest & ASIFormDataRequest to ARC.

In my view controller classes, I often refer to and use properties of the request object in the completion blocks (looking at the response code, response data etc):

__block  ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:SOME_URL]];    
[request setCompletionBlock:^{   

    if([request responseStatusCode] == 200) ....etc

When converting to ARC I get the warning:

Capturing ‘request’ strongly in this block is likely to lead to a
retain cycle

What is the proper way to do this?

Another SO user notes in the previous thread that simply adding __weak may cause the request to be released before the completion of the block, which I believe to be true.

How can I properly reference these properties in completion/failure blocks under ARC?

  • 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-28T05:07:09+00:00Added an answer on May 28, 2026 at 5:07 am

    (I read your comment to the other question)

    After implementing a few more modules using ASIHTTPRequest, I learned that the best way was to keep a strong reference to your request object. In your case, you can do:

    self.request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:SOME_URL]];
    __weak ASIFormDataRequest *weakRequest = self.request; // __block directive not needed since we only access the instance's properties. 
    [self.request setCompletionBlock:^{   
    
        if([weakRequest responseStatusCode] == 200)
        // ...
    

    This way you can still control self.request even after you start the request (e.g. for cancelling). You can do self.request = nil; when you’re ready to release your request, maybe inside your completion block or self.request‘s parent object’s cleanup methods.

    Update:

    If you’re targeting pre-iOS 5, then the common ground stands: use __unsafe_unretained instead of __weak. This is OK because looking at ASIHTTPRequest.m, the blocks are nil‘ed out in its dealloc() (i.e. they shouldn’t get executed). Although I haven’t tested that yet, so make sure to still test with NSZombies enabled.

    Note:

    The only safe way to cancel an ASIHTTPRequest object is to call its clearDelegatesAndCancel method. I’ve been bitten by some nasty bugs when I was just using the plain cancel one.

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

Sidebar

Related Questions

I know that there's a very similar topic for this question, however I'm trying
I know that this question is very similar to the question posted here .
I know that this is a repeated question. I have found very similar questions
I know there is this question that is very similar, but I wanted to
What I am trying to do is very similar to this question: Using jQuery
Very similar to this question (and also this answer ), I'm trying to make
My question is very similar to this one , except I'm trying to capture
[Note: This question is very similar, but not quite the same.] I'm trying to
My question is very similar to this topic . I'm trying to use jquery,
My question is very similar to this question - Addin parameter for Oracle except

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.