0

I need to capture the desktop image and process its RGB Data, i am using Quartz API to do the same,

The problem what i am facing is, high mem usage,

please refer the function ,

Edit here, This function is getting called through pThread ; something like this,

void ImageProcessing::thread(){  
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc]init];  
ImgRef sImageRef  

while( active){  
**strong text**
if ([currentWnd getCurrentRGBImage:&currentImg]){
   /*  do something here */
}

}
[pool release];


}
-(bool)getCurrentRGBImage:(ImgRef *)pImgRef{

    CGImageRef pCGImageRef;
    pCGImageRef = [self getDesktopImage];

    if ( !pCGImageRef ){
        NSLog(@" got NULL Image ");

        CGImageRelease(pCGImageRef);
        pCGImageRef = NULL;

        return NO;
    }

    // Create a bitmap rep from the image...

    size_t width  = CGImageGetWidth(pCGImageRef);
    size_t height = CGImageGetHeight(pCGImageRef);
    int bytesPerRow = CGImageGetBytesPerRow(pCGImageRef);
    int bytesPerPixel = CGImageGetBitsPerPixel(pCGImageRef)/8;

    CGDataProviderRef provider = CGImageGetDataProvider(pCGImageRef);

    CFDataRef pData = CGDataProviderCopyData(provider);
    const uint8_t* bytes = (const uint8_t *)CFDataGetBytePtr(pData);

    /***** ------------- *********

     Copy RAW Bytes to pImgRef

     ****************************/



    CGDataProviderRelease(provider);
    CFRelease(pData);

    CGImageRelease(pCGImageRef);
    pCGImageRef = NULL;

    return YES;

}

and getDesktopImage function is

-(CGImageRef)getDesktopImage{
    CGImageRef screenShot;


        screenShot = CGWindowListCreateImage(CGRectInfinite, kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault);

    return screenShot;
}

The problem is, overall this function is consuming lot of memory, *pImgRef is having one and only one instance, there only pixel , RGB Manipulation,

Memory usage i am referring Mac Activity Monitor, is it reliable ?

the document Documentation for CGDataProviderRelease it is mentioned Application needs to maintain retaining and releasing of it, so i am Calling CGDAtaProviderRelease but getting message in the console malloc reference count underflow for break on auto_refcount_underflow_error to debug

Should i not call CGDataProviderRelease() ? if i comment i don't get this message, so not sure, whether its bug in Quartz or in my code,

Also, this function is consuming hell lot of memory, if i check in the Activity monitor, is it safe to assuming that is really using this much memory ?

Nathaniel Waisbrot
  • 23,261
  • 7
  • 71
  • 99
Amitg2k12
  • 3,765
  • 10
  • 48
  • 97

1 Answers1

1

Since you do not retain, create, or copy the data provider, you should not release it.

I don't see anything that would cause excess memory consumption, but you left some of the code out.

JWWalker
  • 22,385
  • 6
  • 55
  • 76
  • the code that i didn't show thee is no alloc & release call, another thing is, in the activity monitor i am monitoring the mem usage, so is it safe to assume, its showing actual memory consumption, so i should make use of some other tracking tool – Amitg2k12 Jan 09 '13 at 04:19
  • i think above block only consuming memory, i just commented whatever code which i didn't show, but no change in the memory consumption – Amitg2k12 Jan 09 '13 at 07:34
  • I would suggest using Instruments, with the Allocations or Leaks template, to investigate memory usage further. – JWWalker Jan 09 '13 at 18:22
  • Yes, i did it, surprising, using instrumentation, i didn't find much memory consumption and usage as well! , so does that mean, there is something wrong in the way Activity monitor measuring mem usage, the scary part is to the end user, only activity monitor will be visible. – Amitg2k12 Jan 10 '13 at 04:58
  • What numbers are you seeing? Virtual memory or real memory? – JWWalker Jan 10 '13 at 18:20