I have been looking for the solution to solve below problem, but could not find.
I made the filtering method to modify HSV
values of UIImage
. This method is working fine, but
when I use this method, the used memory grows up and they can not be released.
In the box of "Live Bytes" in Instruments, I found the value of CFData
(store) increase
a couple of MB for each filtering. How can I release them??
I found similar question, but not fine for this problem. thank you.
//Objective-C
- (UIImage*)addFilter:(UIImage*)img{
CGImageRef imgRef = img.CGImage;
//getting size
size_t width = CGImageGetWidth(imgRef);
size_t height = CGImageGetHeight(imgRef);
size_t bitsPerComponent = CGImageGetBitsPerComponent(imgRef);
size_t bitsPerPixel = CGImageGetBitsPerPixel(imgRef);
size_t bytesPerRow = CGImageGetBytesPerRow(imgRef);
CGColorSpaceRef colorSpace = CGImageGetColorSpace(imgRef);
CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imgRef);
bool shouldInterpolate = CGImageGetShouldInterpolate(imgRef);
CGColorRenderingIntent renderingIntent = CGImageGetRenderingIntent(imgRef);
CGDataProviderRef dataProvider = CGImageGetDataProvider(imgRef);
CFMutableDataRef *data = CGDataProviderCopyData(dataProvider);
UInt8 *buf = (UInt8 *)CFDataGetMutableBytePtr(data);
double h,s,v;
double c;
double cmax,cmin;
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
/////////////////////
///change HSV value//
/////////////////////
}
}
CFDataRef filterData = CFDataCreate(NULL, buf, CFDataGetLength(data));
CGDataProviderRef filterDataProvider = CGDataProviderCreateWithCFData(filterData);
CGImageRef filterCgImage = CGImageCreate(
width,
height,
bitsPerComponent,
bitsPerPixel,
bytesPerRow,
colorSpace,
bitmapInfo,
filterDataProvider,
NULL,
shouldInterpolate,
renderingIntent
);
UIImage *imgFinal = [UIImage imageWithCGImage:filterCgImage];
CFRelease(filterData);
CGImageRelease(filterCgImage);
CGDataProviderRelease(filterDataProvider);
CFRelease(data);
return imgFinal;
}