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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:46:29+00:00 2026-06-11T13:46:29+00:00

I’m trying to create a visual representation of some data I have. The function

  • 0

I’m trying to create a visual representation of some data I have.

The function I have works and creates the image perfectly (and VERY quickly) but under instruments the Real Memory usage rockets and eventually crashes the app.

I have replaced my function with a return [UIImage imageNamed:@"blah"]; and the memory problems vanish completely.

Was wondering if someone could see why and where the memory is being taken up and how I could possibly free it again?

I have run in instruments under the allocations and leaks tool but nothing shows up in there.

The function is…

- (UIImage*)imageOfMapWithDeadColor:(UIColor *)deadColor aliveColor:(UIColor *)aliveColor
{
//translate colours into rgb components
if ([deadColor isEqual:[UIColor whiteColor]]) {
    dr = dg = db = 255;
} else if ([deadColor isEqual:[UIColor blackColor]]) {
    dr = dg = db = 0;
} else {
    [deadColor getRed:&drf green:&dgf blue:&dbf alpha:&blah];

    dr = drf * 255;
    dg = dgf * 255;
    db = dbf * 255;
}

if ([aliveColor isEqual:[UIColor whiteColor]]) {
    ar = ag = ab = 255;
} else if ([aliveColor isEqual:[UIColor blackColor]]) {
    ar = ag = ab = 0;
} else {
    [aliveColor getRed:&arf green:&agf blue:&abf alpha:&blah];

    ar = arf * 255;
    ag = agf * 255;
    ab = abf * 255;
}

//create bytes of image from the cell map
int yRef, cellRef;

unsigned char *cell_ptr = cells;

for (int y=0; y<self.height; y++)
{
    yRef = y * (self.width * 4);

    int x = 0;
    do
    {
        cellRef = yRef + 4 * x;

        if (*cell_ptr & 0x01) {
            //alive colour
            buffer[cellRef] = ar;
            buffer[cellRef + 1] = ag;
            buffer[cellRef + 2] = ab;
            buffer[cellRef + 3] = 255;
        } else {
            //dead colour
            buffer[cellRef] = dr;
            buffer[cellRef + 1] = dg;
            buffer[cellRef + 2] = db;
            buffer[cellRef + 3] = 255;
        }
        cell_ptr++;
    } while (++x < self.width);
}

//create image
imageRef = CGImageCreate(self.width, self.height, 8, 32, 4 * self.width, CGColorSpaceCreateDeviceRGB(), kCGBitmapByteOrderDefault, provider, NULL, NO, kCGRenderingIntentDefault);

UIImage *image = [UIImage imageWithCGImage:imageRef];

//return image
return image;
}

a few notes…

buffer is an ivar GLubyte malloc-ed in the init.
cells is the original unsigned char array that I’m taking the data from.

Like I said, the function works perfectly (creating the image etc…) I just get a massive usage of memory.

Oh… this function is called LOTS, like 30 times a second or more (which I know will make a difference).

Thanks for any help.

  • 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-11T13:46:31+00:00Added an answer on June 11, 2026 at 1:46 pm

    You use CGImageCreate and the docs say :

    Return Value
    A new Quartz bitmap image. You are responsible for releasing this object by calling CGImageRelease.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
I want to construct a data frame in an Rcpp function, but when I
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text

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.