Search Results

Search found 3 results on 1 pages for 'bbullis21'.

Page 1/1 | 1 

  • iPhone - UIImage Leak, CGBitmapContextCreateImage Leak

    - by bbullis21
    Alright I am having a world of difficulty tracking down this memory leak. When running this script I do not see any memory leaking, but my objectalloc is climbing. Instruments points to CGBitmapContextCreateImage create_bitmap_data_provider malloc, this takes up 60% of my objectalloc. This code is called several times with a NSTimer. //GET IMAGE FROM RESOURCE DIR NSString * fileLocation = [[NSBundle mainBundle] pathForResource:imgMain ofType:@"jpg"]; NSData * imageData = [NSData dataWithContentsOfFile:fileLocation]; UIImage * blurMe = [UIImage imageWithData:imageData]; NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; UIImage * scaledImage = [blurMe _imageScaledToSize:CGSizeMake(blurMe.size.width / dblBlurLevel, blurMe.size.width / dblBlurLevel) interpolationQuality:3.0]; UIImage * labelImage = [scaledImage _imageScaledToSize:blurMe.size interpolationQuality:3.0]; UIImage * imageCopy = [[UIImage alloc] initWithCGImage:labelImage.CGImage]; [pool drain]; // deallocates scaledImage and labelImage imgView.image = imageCopy; [imageCopy release]; Below is the blur function. I believe the objectalloc issue is located in here. Maybe I just need a pair of fresh eyes. Would be great if someone could figure this out. Sorry it is kind of long... I'll try and shorten it. @implementation UIImage(Blur) - (UIImage *)blurredCopy:(int)pixelRadius { //VARS unsigned char *srcData, *destData, *finalData; CGContextRef context = NULL; CGColorSpaceRef colorSpace; void * bitmapData; int bitmapByteCount; int bitmapBytesPerRow; //IMAGE SIZE size_t pixelsWide = CGImageGetWidth(self.CGImage); size_t pixelsHigh = CGImageGetHeight(self.CGImage); bitmapBytesPerRow = (pixelsWide * 4); bitmapByteCount = (bitmapBytesPerRow * pixelsHigh); colorSpace = CGColorSpaceCreateDeviceRGB(); if (colorSpace == NULL) { return NULL; } bitmapData = malloc( bitmapByteCount ); if (bitmapData == NULL) { CGColorSpaceRelease( colorSpace ); } context = CGBitmapContextCreate (bitmapData, pixelsWide, pixelsHigh, 8, bitmapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedFirst ); if (context == NULL) { free (bitmapData); } CGColorSpaceRelease( colorSpace ); free (bitmapData); if (context == NULL) { return NULL; } //PREPARE BLUR size_t width = CGBitmapContextGetWidth(context); size_t height = CGBitmapContextGetHeight(context); size_t bpr = CGBitmapContextGetBytesPerRow(context); size_t bpp = (CGBitmapContextGetBitsPerPixel(context) / 8); CGRect rect = {{0,0},{width,height}}; CGContextDrawImage(context, rect, self.CGImage); // Now we can get a pointer to the image data associated with the bitmap // context. srcData = (unsigned char *)CGBitmapContextGetData (context); if (srcData != NULL) { size_t dataSize = bpr * height; finalData = malloc(dataSize); destData = malloc(dataSize); memcpy(finalData, srcData, dataSize); memcpy(destData, srcData, dataSize); int sums[5]; int i, x, y, k; int gauss_sum=0; int radius = pixelRadius * 2 + 1; int *gauss_fact = malloc(radius * sizeof(int)); for (i = 0; i < pixelRadius; i++) { .....blah blah blah... THIS IS JUST LONG CODE THE CREATES INT FIGURES ........blah blah blah...... } if (gauss_fact) { free(gauss_fact); } } size_t bitmapByteCount2 = bpr * height; //CREATE DATA PROVIDER CGDataProviderRef dataProvider = CGDataProviderCreateWithData(NULL, srcData, bitmapByteCount2, NULL); //CREATE IMAGE CGImageRef cgImage = CGImageCreate( width, height, CGBitmapContextGetBitsPerComponent(context), CGBitmapContextGetBitsPerPixel(context), CGBitmapContextGetBytesPerRow(context), CGBitmapContextGetColorSpace(context), CGBitmapContextGetBitmapInfo(context), dataProvider, NULL, true, kCGRenderingIntentDefault ); //RELEASE INFORMATION CGDataProviderRelease(dataProvider); CGContextRelease(context); if (destData) { free(destData); } if (finalData) { free(finalData); } if (srcData) { free(srcData); } UIImage *retUIImage = [UIImage imageWithCGImage:cgImage]; CGImageRelease(cgImage); return retUIImage; } The only thing I can think of that is holding up the objectalloc is this UIImage *retUIImage = [UIImage imageWithCGImage:cgImage];...but how to do I release that after it has been returned? Hopefully someone can help please.

    Read the article

  • iPhone - UIImage imageScaledToSize Memory Issue

    - by bbullis21
    I have done research and tried several times to release the UIImage memory and have been unsuccessful. I saw one other post on the internet where someone else was having this same issue. Everytime imageScaledToSize is called, the ObjectAlloc continues to climb. In the following code I am pulling a local image from my resource directory and resizing it with some blur. Can someone provide some help on how to release the memory of the UIImages called....scaledImage and labelImage. This is the chunk of code where the iPhone Intruments has shown to have the ObjectAlloc build up. This chunk of code is called several times with an NSTimer. //Get local image from inside resource NSString * fileLocation = [[NSBundle mainBundle] pathForResource:imgMain ofType:@"jpg"]; NSData * imageData = [NSData dataWithContentsOfFile:fileLocation]; UIImage * blurMe = [UIImage imageWithData:imageData]; //Resize and blur image UIImage * scaledImage = [blurMe _imageScaledToSize:CGSizeMake(blurMe.size.width / dblBlurLevel, blurMe.size.width / dblBlurLevel) interpolationQuality:3.0]; UIImage * labelImage = [scaledImage _imageScaledToSize:blurMe.size interpolationQuality:3.0]; imgView.image = labelImage;

    Read the article

  • iPhone - dealloc subview UIViewController when removeFromSuperview

    - by bbullis21
    I have several buttons on my main UIViewController (main menu) that creates and adds a subview UIViewController on top of the main menu. When I remove the subview the memory from that controller is not released. How can I release that subviews memory instantly? Does anyone have an example? This would solve all my problems! Thanks in advance. Here is how I add a subview if((UIButton *) sender == gameClassicBtn) { GameClassic *gameClassicController = [[GameClassic alloc] initWithNibName:@"GameClassic" bundle:nil]; self.gameClassic = gameClassicController; [gameClassicController release]; [self.view insertSubview:gameClassicController.view atIndex:1]; }

    Read the article

1