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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:46:01+00:00 2026-06-06T08:46:01+00:00

I am fairly experienced C programmer but IOS is new for me. I do

  • 0

I am fairly experienced C programmer but IOS is new for me. I do have memory leak (I think this because I get MemoryWarning and soon my app gets killed with no mercy). But Instruments memory leak detector says all is fine. Yes, I have memory snapshotting running every X seconds. Meanwhile if I run VM Tracker I see memory usage is going up. Most of memory is taken by “CG Image” which seems to be clue. I used “if 0”-s to narrow down to place where leak occurs, so this is it:

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { 

    UIImage *image = [self imageFromSampleBuffer:sampleBuffer];
#if 1
    /****** Draw stuff on every frame screen *******/
    CGImageRef imageRef = image.CGImage;

    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
    CGContextRef context = CGBitmapContextCreate(NULL, image.size.width, image.size.height, 8, image.size.width * 4, colorSpaceRef,kCGImageAlphaPremultipliedLast | kCGBitmapByteOrderDefault);    
    CGContextDrawImage(context, CGRectMake(0, image.size.height*-0.1, image.size.width, image.size.height*1.2 ),imageRef);
#endif

#if 0
    if (backgroundJobRunning1 == NO) {
        backgroundJobRunning1 = YES;

        NSValue *value1 = [NSValue valueWithPointer:image];
        // start1 = [NSDate timeIntervalSinceReferenceDate];
        NSArray *array = [NSArray arrayWithObjects:value1, nil];
//        [self performSelectorInBackground:@selector(cleverStuffWithImage:) withObject:array ];
        [self cleverStuffWithImage:(array)];
    }
#endif
    if(sum>0) {
        CGPoint p1= CGPointMake(image.size.height-mycorners[0].y ,image.size.width-mycorners[0].x );
        CGPoint p2= CGPointMake(image.size.height-mycorners[1].y ,image.size.width-mycorners[1].x );
        CGPoint p3= CGPointMake(image.size.height-mycorners[2].y ,image.size.width-mycorners[2].x );
        CGPoint p4= CGPointMake(image.size.height-mycorners[3].y ,image.size.width-mycorners[3].x );
        [_layer setpoints:p1 withArg2:p2 withArg3:p3 withArg4:p4];
    }

    /***** Release everything we allocated */
#if 0
    CGImageRef cgImage = CGBitmapContextCreateImage( context );
 //   imageRef = (CGImageRef)[[(id)imageRef retain] autorelease];

    UIImage *image2 = [[UIImage alloc] initWithCGImage:cgImage];
    if(_settingImage == NO) {
        _settingImage = YES;
        [self performSelectorInBackground:@selector(setImageToView:) withObject:image2];
    } else {
        CCLOG(@"missed frame");
    }

    CGImageRelease(cgImage);
#endif

#if 1
    CGColorSpaceRelease( colorSpaceRef );
    CGContextRelease( context );
#endif
}
#if 0
- ( IplImage * )createGrayIplImage: ( UIImage * )image {
    CGImageRef imageRef  = image.CGImage;
    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
    IplImage * iplImage  = cvCreateImage( cvSize( image.size.width, image.size.height ), IPL_DEPTH_8U, 4 );
    CGContextRef context = CGBitmapContextCreate(iplImage->imageData,
                                          iplImage->width,
                                          iplImage->height,
                                          iplImage->depth,
                                          iplImage->widthStep,
                                          colorSpaceRef,
                                          kCGImageAlphaPremultipliedLast | kCGBitmapByteOrderDefault
                                          );

    CGContextDrawImage( context, CGRectMake(0, 0, image.size.width, image.size.height), imageRef);
    CGContextRelease( context );
    CGColorSpaceRelease( colorSpaceRef );

    IplImage * returnImage = cvCreateImage( cvGetSize( iplImage ), IPL_DEPTH_8U, 1 );
    cvCvtColor( iplImage, returnImage, CV_RGBA2GRAY );
    cvReleaseImage( &iplImage );
    return returnImage;
}
#endif
- (void)dealloc {
    [[CCDirector sharedDirector] end];
    [window release];
    [super dealloc];
}

Leaks happens when “#if 1”-s are like now. What I am not releasing?

Actually I had more of similar problems and I assume there is something I do not know about UIImage and CGImage relationship. For example I do not clearly understand if “CGImageRef imageRef = image.CGImage;” allocates something and when it gets released. Trying to release it caused double free error. Meanwhile I pass sometime one of these to background thread and got memory leaks.

  • 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-06T08:46:02+00:00Added an answer on June 6, 2026 at 8:46 am

    Hmm, seems like adding

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    

    to beginning and

    [pool release]
    

    made problem go away. I didn’t knew it handles this like thread.

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

Sidebar

Related Questions

I have plenty of experience with this in PHP, but am fairly new to
I'm a fairly experienced programmer, but new to GUI programming. I'm trying to port
I'm a fairly experienced .NET desktop developer, but I'm new to Silverlight. I'm trying
I'm fairly new to Silverlight but experienced in web development, and I'm finding myself
I am a fairly experienced OpenMP user, but I have just run into a
I am new to Symfony+Doctrine, but fairly experienced with web application development in general
I am a completely new to JPA+Hibernate+Spring (but I have a fairly much experience
I'm fairly new to Perforce but I already have experience with DVCS like Git
I am fairly new to Rails, but I am pretty experienced with Ruby. Can
Fairly new to programming. I just can't wrap my head around how to get

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.