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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:52:30+00:00 2026-05-15T10:52:30+00:00

Hey guys, suppose the following code: int main (int argc, const char * argv[])

  • 0

Hey guys, suppose the following code:

int main (int argc, const char * argv[]) 
{
//[...]
    Rectangle* myRect  = [[Rectangle alloc] init];

    Vector2* newOrigin = [[[Vector2 alloc] init] autorelease]; // ref count 1

    [newOrigin setX: 50.0f];
    [myRect setOrigin: newOrigin];    // ref count 2

    [myRect.origin setXY: 25.0f :100.0f]; // ref count goes to 3... why ?

    [myRect release];

    [pool drain];
    return 0;
}

Rectangle’s origin is declared as a (retain) synthesized property.
Just wondering 2 things:

  1. Why does ref count goes to 3 when using the getter accessor of Rectangle’s origin? Am I doing something wrong ?
  2. With a ref count of 3, I don’t understand how this snippet of code cannot leak. Calling release on myRect will make it go down to 2 since I call release on the origin in dealloc(). But then, when does autorelease take effect?

Thanks!

  • 1 1 Answer
  • 2 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-15T10:52:31+00:00Added an answer on May 15, 2026 at 10:52 am

    Why does ref count goes to 3 when
    using the getter accessor of
    Rectangle’s origin?

    Because your @property is declared as atomic (the default) and, thus, the synthesized getter retains and then autoreleases the return value.

    Am I doing something wrong ?

    Yes. You are studying absolute retain counts.

    The absolute retain counts of any object is quite thoroughly useless to consider. You only care about deltas; if you cause the retain count to increase, you must cause it to decrease.

    With a ref count of 3, I don’t
    understand how this snippet of code
    cannot leak. Calling release on myRect
    will make it go down to 2 since I call
    release on the origin in dealloc().
    But then, when does autorelease take
    effect?

    An autorelease is simply a delayed release that kicks in when the containing pool is drained. So, in your case, the object will be deallocated when [pool drain]; is executed.

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

Sidebar

Related Questions

Hey guys I'm working on a jQuery code snippet that's suppose to remove a
Hey guys this is my html code: <div class=nakupy> <li class=icn_kategorie><a href=#>Nákupy</a> <div class=sub_menu>
hey guys I have the follow code in js: $(document).ready(function(){ $(.replyLink).click(function(){ $(#form-to-+this.id).html(htmlForm()).toggle(500); return false;
Hey guys I'm following the rails tutorial found here http://net.tutsplus.com/tutorials/ruby/the-intro-to-rails-screencast-i-wish-i-had/ and I've gotten to
Hey guys, I have a problem with a code that I've been writing. I
Code updated to working version. Thanks again for the help :) Hey guys. I
Hey guys I have the following while loop which seems not to stop. It's
Hey guys, I'm just starting out with GWT and am getting the following error
hey guys, i'm getting an exception on the following inner exception: {Value cannot be
hey guys having this really simple problem but cant seem to figure out have

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.