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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:43:40+00:00 2026-06-09T07:43:40+00:00

I have custom UIView drawing in drawRect . I don’t know the C APIs

  • 0

I have custom UIView drawing in drawRect.

I don’t know the C APIs that well so I’m not sure what memory rules they require. The Objective-C rules are pretty simple and state that you release anything you own via init retain or copy but the C function CGGradientCreateWithColorComponents is not Objective-C and the Product > Analyze reports that it is a potential leak.

Is it necessary to release the results of this function, and if so, how? And in general, when it comes to these APIs, is there any easy way to know if a function is allocating memory that you need to manually release?

UPDATE: Here is the code, thanks to the information in the answers so far. I’m getting incorrect decrement error now:

CGGradientRef theGradient=[self makeGradient:YES];
//do something with theGradient in my drawing
CGGradientRelease(theGradient); // this line Analyze says incorrect decrement of object not owned by caller

And in makeGradient I have:

 - (CGGradientRef)makeGradient:(BOOL)red{
     CGGradientRef gradient;
     //create my gradient
     return gradient;
 }
  • 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-09T07:43:42+00:00Added an answer on June 9, 2026 at 7:43 am

    The general rule is that if you call function whose name contains “Create” or “Copy”, you must release the object that it returns. This is called the “Create rule”.

    You created the gradient using a function that has “Create” embedded in the name. That means you’re responsible for releasing the gradient. You can use CGGradientRelease or CFRelease.

    You can read about the Create rule and other memory management conventions in the Memory Management Programming Guide for Core Foundation.

    You can also read Quartz 2D Programming Guide: Memory Management: Object Ownership.

    UPDATE

    Based on your new code samples, I now see that you need to learn about another memory management convention. ;^)

    Objective-C methods use a slightly different naming convention than Core Foundation functions. Instead of putting “Create” or “Copy” in the name, the convention for Objective-C methods is that the name must start with “alloc”, “new”, “copy”, or “mutableCopy” if it returns an object that the caller must release. (You can read about Objective-C memory management conventions here.)

    Change the name of your method from makeGradient: to newGradient: and the analyzer will stop complaining. I tested it! :^)

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

Sidebar

Related Questions

I have a custom UIView that contains an interactive drawing that is drawn in
I have a simple custom UIView (a rectangle) that is implemented with drawRect. The
I have a UIView subclass that I am doing some custom drawing in. When
I have a class that subclasses UIView called DrawView. This class contains custom drawing
I have a variable sized UIView with a drawRect containing CoreGraphics custom drawing code.
I have a UIScrollView that contains a custom UIView. In my UIView I am
I have a custom UIView. It initializes two rectangular UIBezierPaths, and in drawRect it
I have a custom UIView class, and in the - (void)drawRect:(CGRect)rect I want to
I'm drawing a custom UIView that is sitting inside a xib whose ViewController is
I have created a UIView subclass in order to implement a custom drawRect method.

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.