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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:54:49+00:00 2026-05-16T06:54:49+00:00

I created a simple program to test the retain/release methods in Objective-C memory management.

  • 0

I created a simple program to test the retain/release methods in Objective-C memory management. As I understand of ObjC memory management, I expect that a object with retain count = 1 on which I call release get the retain count decremented to zero and then released. But this test program show that after the first release I still get retain count = 1:

// TestClass.h
#import <Cocoa/Cocoa.h>
@interface TestClass : NSObject {
}
@end

// TestClass.m
#import "TestClass.h"
@implementation TestClass
@end

// RetainRelease.m
#import <Foundation/Foundation.h>
#include "TestClass.h"

void dumpRetain(id o);

int main (int argc, const char * argv[]) {
    TestClass *s = [[TestClass alloc] init];
    dumpRetain(s);

    [s release];
    dumpRetain(s);
}

output:

2010-08-13 17:42:45.489 RetainRelease[20933:a0f] NSString - retain count=1
2010-08-13 17:42:45.491 RetainRelease[20933:a0f] NSString - retain count=1

Someone could explain that?
Thanks

  • 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-16T06:54:49+00:00Added an answer on May 16, 2026 at 6:54 am

    Why should it decrement to zero? When you release an object with a retain count of 1, the object is destroyed, so it doesn’t have a retainCount anymore. As such, why bother changing something to zero when it’s going to go away a couple of nanoseconds later?

    Also, don’t think about stuff in terms of retainCount. You’ll end up killing yourself out of frustration. Instead think about “do I own this object? If I do, do I properly relinquish ownership of this object when I’m done with it?”

    If you can answer those questions properly then that’s all you need to do.

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

Sidebar

Related Questions

I've created simple program to test Threads in Java. I'd like it to print
I created 2 simple console program and a simple structure. M11 Object is the
I've created a simple test app (Python 2.6.1) that runs a ThreadingTCPServer, based on
I have created a simple WPF test program, based on what Visual Studio gives
I created a simple program that takes the path of a directory as an
I have created a very simple dummy program to understand Delegates and events. In
I have created this simple program to learn shared_ptr using namespace std; #define Yes
I've created this simple example program, but this doesn't work. it won't connect. any
I created a simple WCF demo: Server Side: namespace ServerSide { class Program {
I am attempting to create a simple program that will keep a text log

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.