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 8637439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:28:59+00:00 2026-06-12T10:28:59+00:00

I don’t truly understand the difference between weak and strong pointer. It doesn’t cause

  • 0

I don’t truly understand the difference between weak and strong pointer.
It doesn’t cause any big problem until now I am following an example in the documentation, making an NSURLRequest and use it in NSURLConnection to received data.

The code is like this:

    //create the request with url
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:3000/students.json"]];

    //create the with the request
    NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];


    if (connection) {
        //create NSData instance to hold data if connection is successfull
        self.receivedData = [[NSMutableData alloc]init];
//        NSLog(@"%@",@"Connection successfully");
    }
    else{
        NSLog(@"%@",@"Connection failed");
    }

SO I append data into receivedData in the body of delegate method.

@property (strong,nonatomic) NSMutableData *receivedData;

//delegate method
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
    [self.receivedData appendData:data];
    NSLog(@"%@",@"Receiving Data");
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
    NSLog(@"Succeeded! Received %d bytes of data",[self.receivedData length]);
}

the code I posted above is working:) because I have just fixed it.

My question is – The type of the pointer was original weak. I would always get 0 bytes of data from [self.receivedData length] before I have changed the type of pointer from weak to strong and I don’t understand why it can’t hold the data.

  • 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-06-12T10:29:01+00:00Added an answer on June 12, 2026 at 10:29 am

    A weak reference doesn’t hold onto its contents. You were telling the receivedData variable to look at the mutable data object you created, but not to hold onto it. So when that if block completed, the data’s scope ended and ARC released it; there was nothing else holding onto it so it was deallocated and receivedData was set to nil, because it no longer had anything to point to. [self.receivedData length] returned 0 (technically nil) because self.receivedData was nil. By declaring receivedData strong, you told it to hold onto the object it points to, making sure it stays around until you’re done with it.

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

Sidebar

Related Questions

Don't be scared of the extensive code. The problem is general. I just provided
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't be afraid to use any technical jargon or low-level explanations for things, please.
Don't know why this doesn't work. I can't do implicit animation for a newly
Don't know if this is an eclipse specific problem but whenever I declare a
I don't understand the complexities related to CrLf settings in git: core.autocrlf , core.safecrlf
Don't understand this simple code: def main(): print (This program illustrates a chaotic function)
don't understand: in my controller: @json = User.all.to_gmaps4rails do |user| \Title\: \#{user.email}\ end in
Don't understand, if Data.Map is and [] is. I found this out while wondering
Don't quite understand determinism in the context of concurrency and parallelism in Haskell. Some

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.