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

  • Home
  • SEARCH
  • 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 8596367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:39:42+00:00 2026-06-12T00:39:42+00:00

I enabled zombies with my Xcode to find if my process crashes to a

  • 0

I enabled zombies with my Xcode to find if my process crashes to a memory leak. Here is a code snippet:

- (NSString *)facVersion
{
    return facVersion;
}


- (void) setFacVersion:(NSString*)_facVersion
{
    if(facVersion != nil) [facVersion release];
    facVersion = [_facVersion retain];
}

Now when I call

NSLog(@"%@", facVersion);
[self setFacVersion:facVersion];

the code crashes with the message

[CFString retain]: message sent to deallocated

Do you know what the problem is?

  • 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-12T00:39:44+00:00Added an answer on June 12, 2026 at 12:39 am

    This is a typical problem with badly written setters. When the object itself is the last owner of the backing ivar of the property, assigning the property to itself causes a release effectively deallocating the object, then a retain on the same deallocated object. You can fix this in two ways. Either check for the to-be-assigned object not being the same as the current value of the property, or retain first and release only after. All in all, solution one:

    - (void) setFacVersion:(NSString*)_facVersion
    {
        if (facVersion == _facVersion) return;
        [facVersion release];
        facVersion = [_facVersion retain];
    }
    

    Soltion two:

    - (void) setFacVersion:(NSString*)_facVersion
    {
        [_facVersion retain];
        [facVersion release];
        facVersion = _facVersion;
    }
    

    By the way, checking for an object not being nil before releasing it is superfluous. Objective-C is not Java.

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

Sidebar

Related Questions

I think I've got a memory leak, I've enabled zombies and in profiler it
I enabled heap debugging because of a memory leak error I started seeing in
I enabled heap debugging to try and debug some memory leak errors. I do
I've enabled mod_rewrite, restarted all services, still not taking affect. Here's what I have
I have this code in one of my NSManagedObjects : if (self.tempImageStorage) { return
When I run Project/Profile in Xcode and choose Zombies , the app runs in
I have Automatic Reference Counting and Zombies enabled... I keep getting EXC BAD ACCESS
I have used the following code. MainView.h: NSString *sCopySource; NSString *sFileSource; // retain and
I enabled inline editing on SitEdit 2009 SP2 using the answer given here How
I enabled the nszombie in xcode 4.2. (from product->editScheme) I have got this message:

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.