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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:12:30+00:00 2026-06-12T05:12:30+00:00

I am getting memory leak warnings for these two methods. The second one calls

  • 0

I am getting memory leak warnings for these two methods. The second one calls the first one and apparently its leaking memory. Any ideas?

static UIColor *subtreeBorderColor(void) 
{
    return [UIColor colorWithRed:0.0f green:0.5f blue:0.0f alpha:1.0f];
}


- (void) updateSubtreeBorder 
{
    CALayer *layer = [self layer];
    if (layer) {


        // If the enclosing TreeGraph has its "showsSubtreeFrames" debug feature enabled, 
        // configure the backing layer to draw its border programmatically.  This is much more efficient
        // than allocating a backing store for each SubtreeView's backing layer, only to stroke a simple
        // rectangle into that backing store.

        PSBaseTreeGraphView *treeGraph = [self enclosingTreeGraph];
        if ([treeGraph showsSubtreeFrames]) {
            [layer setBorderWidth:subtreeBorderWidth()];
            [layer setBorderColor:[subtreeBorderColor() CGColor]];

        } else {
            [layer setBorderWidth:0.0];
        }


    }
}

//3: Potential leak of an object
//6: Calling 'subtreeBorderColor'
//1: Entered call from 'updateSubtreeBorder'
//13: Method returns an Objective-C object with a +0 retain count
//12: Reference count incremented. The object now has a +1 retain count
//6: Returning from 'subtreeBorderColor'
//13: Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1

UPDATE 2: I just completely changed the code and deleted temporary files and cleaned the solution and this is what I see – it is finding errors where there isn’t even code

enter image description here

  • 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-12T05:12:32+00:00Added an answer on June 12, 2026 at 5:12 am

    Simple. You don’t need the call to - retain in the function. That’s exactly what the autorelease pattern is invented for. Since you don’t create the UIColor object using alloc-init, you don’t take ownership of it. No need to superfluously complicate memory management further. 🙂

    Edit: (to prevent future downvotes) now that you edited your question and code so that it no longer erroneously returns a retained object, the previous statement is no longer valid. Yes, Xcode shows this notice about the memory leak where “there isn’t even code”, and that’s strange. Yes, perhaps a compiler bug. Still, a temporary (and in my opinion, perfectly valid) workaround is to simply use a define instead of a function. Let’s see what Xcode says if you write this instead:

    #define SUBTREE_BORDER_COLOR [UIColor colorWithRed:0.0f green:0.5f blue:0.0f alpha:1.0f]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting the memory leak in my objects setters can any one help
First of all I am getting memory leak while scrolling tableview out of bounds.
Im getting the same memory leak as I mentioned the link below. NSXMLParser Leaking
why i'm getting the memory leak errors without allocating or adding any elements to
I'm getting the memory leak message upon shutdown, saying that I'm leaking 3 of
HI, I am getting memory leak at NSObject allocation i.e., ContactDTO* contactDTO = [[ContactDTO
Tested app in Instrumens for memory leak getting multiple leaks for using multiple times
Using Instruments, I keep on getting pointed to a memory leak with a UIImage.
I've being getting a memory leak warning with a UITabbarcontroller. If I release the
I am getting memory leak at text fiels please suggest me how to resolve

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.