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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:54:57+00:00 2026-06-01T09:54:57+00:00

Doing code analysis of the project and get the message Reference-counted object is used

  • 0

Doing code analysis of the project and get the message “Reference-counted object is used after it is released” on the line [defaults setObject: deviceUuid forKey: @ “deviceUuid”];

I watched this topic
Obj-C, Reference-counted object is used after it is released?
But the solution is not found. ARC disabled.

// Get the users Device Model, Display Name, Unique ID, Token & Version Number
UIDevice *dev = [UIDevice currentDevice];
NSString *deviceUuid;
if ([dev respondsToSelector:@selector(uniqueIdentifier)])
    deviceUuid = dev.uniqueIdentifier;
else {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    id uuid = [defaults objectForKey:@"deviceUuid"];
    if (uuid)
        deviceUuid = (NSString *)uuid;
    else {
        CFStringRef cfUuid = CFUUIDCreateString(NULL, CFUUIDCreate(NULL));
        deviceUuid = (NSString *)cfUuid;
        CFRelease(cfUuid);
        [defaults setObject:deviceUuid forKey:@"deviceUuid"];
    }
}

Please help find the cause.

  • 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-01T09:54:59+00:00Added an answer on June 1, 2026 at 9:54 am

    The problems is here:

        CFStringRef cfUuid = CFUUIDCreateString(NULL, CFUUIDCreate(NULL));
        deviceUuid = (NSString *)cfUuid;
        CFRelease(cfUuid);
        [defaults setObject:deviceUuid forKey:@"deviceUuid"];
    

    Let’s go through what this actually does:

        CFStringRef cfUuid = CFUUIDCreateString(NULL, CFUUIDCreate(NULL));
    

    A CFUUID is created (and leaked). A CFStringRef is created and assigned to cfUuid. (Note: The name cfUuid implies that cfUuid is a CFUUIDRef. Of course, it isn’t; it’s a CFStringRef.)

        deviceUuid = (NSString *)cfUuid;
    

    That same CFStringRef is type cast and assigned to deviceUuid. This is not a new instance of NSString or CFStringRef, it’s just a typecast of the same instance.

        CFRelease(cfUuid);
    

    You release the CFStringRef. Since the NSString points to the same object, you also release it.

        [defaults setObject:deviceUuid forKey:@"deviceUuid"];
    

    And here, you use the typecasted object, which was released before.

    THe simplest fix to the stale pointer is this:

        CFStringRef cfUuid = CFUUIDCreateString(NULL, CFUUIDCreate(NULL));
        deviceUuid = (NSString *)cfUuid;
        [defaults setObject:deviceUuid forKey:@"deviceUuid"];
        CFRelease(cfUuid);
    

    But this code is dangerous, and you already know why: deviceUuid is also invalid. But this isn’t obvious, so you can trip on it later. Also, it doesn’t fix the CFUUID leak.

    To fix the CFStringRef leak, you could use this:

        deviceUuid = (NSString *)CFUUIDCreateString(NULL, CFUUIDCreate(NULL));
        [defaults setObject:deviceUuid forKey:@"deviceUuid"];
        [deviceUuid autorelease]; // or release, if you don't need it in code not
                                  // included in your post
    

    However, this still doesn’t fix the CFUUID leak.

        CFUUIDRef cfuuid = CFUUIDCreate(NULL);
        deviceUuid = (NSString *)CFUUIDCreateString(NULL, cfuuid);
        CFRelease(cfuuid);
        [defaults setObject:deviceUuid forKey:@"deviceUuid"];
        [deviceUuid autorelease]; // or release, if you don't need it in code not
                                  // included in your post
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When running code analysis on my project, I receive the following message: CA1051 :
I am looking at doing some static code analysis of an exisiting PHP project,
What are the benefits of doing static code analysis on your source code? I
We're doing some code cleanup, fixing signed/unsigned comparisons, running static analysis, etc, on the
while doing some static code analysis I've found a weird one. On a call
Premise When using code analysis (or fxCop) with C# optional parameters you can get
I am doing a code review of a web project and want to make
Previously, when running a Code Analysis on my project, I thought the context men
Tried to run Run Code Analysis on a project here, and got a number
I am doing static code analysis (Using Gimpel PC- Lint) of my source code.

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.