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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:05:37+00:00 2026-05-13T17:05:37+00:00

I have a query regarding the memory management. Let’s begin with an example. Assume

  • 0

I have a query regarding the memory management.

Let’s begin with an example. Assume we have a class as follows.

@interface myClass : NSObject {
    NSString *xyz;
}
@end

Now, see the implementation.

@interface myClass : NSObject {
    NSString *xyz;
}
@end

@implementation myClass
-(void)abc{
    // xyz allocted here
}
-(void)pqr{
    // retained or copied many times or may not a single time
}
-(void)mno{
    // retained or copied many times or may not a single time
}
-(void)jpg{
    // may be released more than one time or may be not
}


//-(void)dealloc{
//  [xyz release];
//  [super dealloc];
//}
//
//-(void)dealloc{
//  if(xyz!=nil && [xyz retainCount]>0){ [xyz release]; xyz=nil; }
//  [super dealloc];
//}

-(void)dealloc{
    if(xyz!=nil){ 
        while([xyz retainCount]>0) 
           [xyz release]; 
        xyz=nil; 
    }
    [super dealloc];
}
@end

In above code. I have three dealloc functions. Which one is preferable? If none of these, then please suggest yours.

I am confused because Objective C says, object must be released each time = each time alloc/retained.

But most of the sample code has just single statement “[xyz release];” doesn’t it create a memory leak?

  • 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-13T17:05:37+00:00Added an answer on May 13, 2026 at 5:05 pm
    - (void)dealloc {
        [xyz release];
        [super dealloc];
    }
    

    …is the correct version. In Objective-C, you generally shouldn’t use the retainCount method.

    If you want to be very safe, you can also write:

    - (void)dealloc {
        [xyz release], xyz = nil;
        [super dealloc];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 342k
  • Answers 342k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your web.xml and <form> are all perfectly fine. The servlet… May 14, 2026 at 5:06 am
  • Editorial Team
    Editorial Team added an answer First you shoud maybe read this article. When you use… May 14, 2026 at 5:06 am
  • Editorial Team
    Editorial Team added an answer All objects are created inside threads. Every instruction ever executed… May 14, 2026 at 5:06 am

Related Questions

I'm trying to find out how much memory my own .Net server process is
I have a query that contains about 10 joins. Using a List View and
.NET 3.5, C# I have a web app with a search feature. Some of
I've been working with databases for the last few years and I'd like to
I am working on a Django application which allows a user to upload files.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.