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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:15:09+00:00 2026-06-04T17:15:09+00:00

If I have a code looked like this: -(void) func { ObjectA* A =

  • 0

If I have a code looked like this:

     -(void) func {  
         ObjectA* A = [[ObjectA alloc]init];  

        [something doSomething:blah andDelegate: A]; 

    }

Assuming the call of doSomething will make a http request call so the delegate will be called only when it received response from the server. In this case, there would be a delay.
Note: something is an instance variable of a class.

If I call ‘func’ twice, will the first initialized of A be leaked before it received the response on the delegate. Assuming there is a release operation when calling the delegate function when received the responsed.

The reason I thinking of this is because if second initialized of ‘A’ passed in to something as an delegate before the first delegate finished it’s role. Will second initialized of ‘A’ replaced the first initialized of ‘A’?

  • 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-04T17:15:11+00:00Added an answer on June 4, 2026 at 5:15 pm

    Yes, if you’re not compiling with ARC, you have a leak. You’re creating an object with alloc, which means that you own it, and you’re not relinquishing that ownership by sending release. This is the core memory management rule for Cocoa.

    It may be that the object, something, to which you’re passing A, also needs to own A (in fact, it sounds like that is the case). If so, something should send retain to A and then send release when it no longer needs A.

    Will second initialized of ‘A’ replaced the first initialized of ‘A’?

    Sort of. The name A is only valid inside this method. When you create an object and assign it to A, and then that name goes out of scope, you can’t refer to the object anymore. That’s what a leak is. When you run this method again, essentially a new name A is created and you assign another object to it.

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

Sidebar

Related Questions

I have spotted something like this in code: void foo(IList<int>^ const & list )
Suppose I have code something like this: #include boost/thread/mutex.hpp using boost::mutex; typedef mutex::scoped_lock lock;
I have just refactored a colleague's code that, roughly, looked like this... public class
Suppose I have some code like this: class Visitor { public: Visitor(callBackFunction) {} void
I have code that looks like this: template<class T> class list { public: class
I have code that I want to look like this: List<Type> Os; ... foreach
I have code like this var MyObj = { f1 : function(o){ o.onmousedown =
I have code similar to the following with a URL like this... If I
I have a C++ application that can be simplified to something like this: class
I'm implementing producer/consumer problem. the code looks like this: void producer() { // produce

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.