Objective c NSCalibratedRGBColor在mosaic程序中占用内存

Objective c NSCalibratedRGBColor在mosaic程序中占用内存,objective-c,macos,cocoa,mosaic,Objective C,Macos,Cocoa,Mosaic,首先,我是一个新手,所以我感谢你的耐心 我正在尝试开发我自己的照片马赛克程序——对我来说,这是一次学习之旅 作为程序的一部分,我试图枚举一个图像文件夹,计算图像像素的平均值RGB,将该数据存储在NSDictionary对象中,然后为数组中的每个图像收集NSDictionary 在我尝试学习的时候,代码有点像打瞌睡的方式——我还没有发现任何内置的错误捕获 然而,代码是有效的,当我在仪器中运行时,我得到了大量的NSCalibratedRGBColor对象的分配,这些对象在例程结束时似乎没有被释放 欢

首先,我是一个新手,所以我感谢你的耐心

我正在尝试开发我自己的照片马赛克程序——对我来说,这是一次学习之旅

作为程序的一部分,我试图枚举一个图像文件夹,计算图像像素的平均值
RGB
,将该数据存储在
NSDictionary
对象中,然后为数组中的每个图像收集
NSDictionary

在我尝试学习的时候,代码有点像打瞌睡的方式——我还没有发现任何内置的错误捕获

然而,代码是有效的,当我在仪器中运行时,我得到了大量的
NSCalibratedRGBColor
对象的分配,这些对象在例程结束时似乎没有被释放

欢迎就如何处理此内存问题提供任何想法/指导

我使用以下代码来计算平均RGB

while (tempFile = [dirEnum nextObject]) {

    //need to process the images within this while loop
    if ([filesAllowed containsObject:[tempFile pathExtension]]) {
        count = count + 1;
        test = [NSString stringWithFormat:@"%@/%@", imageSourceFilePath, tempFile];
        tempFileURL = [NSURL fileURLWithPath:test];

        CIImage *sourceCIImage = [[CIImage alloc] initWithContentsOfURL:tempFileURL];
        NSBitmapImageRep *tempBitmapImageRep = [[NSBitmapImageRep alloc] initWithCIImage:sourceCIImage];
        NSInteger imageHeight = [tempBitmapImageRep pixelsHigh];
        NSInteger imageWidth = [tempBitmapImageRep pixelsWide];
        int totalPixels = (int)imageWidth * (int)imageHeight;

        countPixelsWide = 0;
        countPixelsHigh = 0;
        totalGreen = 0;
        totalBlue = 0;
        totalRed = 0;

        //work out averages - iterate over each column
        while (countPixelsWide < imageWidth) {
            while (countPixelsHigh < imageHeight) {
                tempColor = [tempBitmapImageRep colorAtX:countPixelsWide y:countPixelsHigh];
                [tempColor getRed:&tempRed green:&tempGreen blue:&tempBlue alpha:&tempAlpha];
                totalRed = totalRed + tempRed;
                totalBlue = totalBlue + tempBlue;
                totalGreen = totalGreen + tempGreen;
                countPixelsHigh = countPixelsHigh + 1;
            }
            countPixelsWide = countPixelsWide + 1;
            countPixelsHigh = 0;
        }

        //calculate averages - re-use total variables
        totalRed = totalRed/totalPixels;
        totalBlue = totalBlue/totalPixels;
        totalGreen = totalGreen/totalPixels;


        //create dictionary for each source image and then add to sourceImageArray for later reference
        dictOfSourceImages = [self makeDictionaryRecord:tempFileURL withAverageRed:[NSNumber numberWithFloat:totalRed] withAverageBlue:[NSNumber numberWithFloat:totalBlue] withAverageGreen:[NSNumber numberWithFloat:totalGreen]];
        [sourceImageData addObject:dictOfSourceImages];
    }
}
while(tempFile=[dirEnum nextObject]){
//需要在此while循环中处理图像
如果([FileAllowed containsObject:[tempFile pathExtension]]){
计数=计数+1;
测试=[NSString stringWithFormat:@“%@/%@”,imageSourceFilePath,tempFile];
tempFileURL=[NSURL fileURLWithPath:test];
CIImage*sourceCIImage=[[CIImage alloc]initWithContentsOfURL:tempFileURL];
NSBitmapImageRep*tempBitmapImageRep=[[NSBitmapImageRep alloc]initWithCIImage:sourceCIImage];
NSInteger imageHeight=[tempBitmapImageRep pixelsHigh];
NSInteger imageWidth=[tempBitmapImageRep像素宽度];
int totalPixels=(int)图像宽度*(int)图像高度;
countPixelsWide=0;
countPixelsHigh=0;
totalGreen=0;
totalBlue=0;
totalRed=0;
//计算平均值-迭代每列
while(countPixelsWide
我也遇到了同样的问题-你解决过这个问题吗?没有-我没有解决这个问题。