多个图像合并导致iPad中的内存泄漏

时间:2013-08-08 07:34:34

标签: ios ipad memory-management memory-leaks uigraphicscontext

我正在使用AVAudioRecorder并行录制语音,我正在以1秒的间隔运行NStimer,其功能是将多个图像合并为一个并将其添加到NSmutablearray中以便将来将这些图像用于视频(MP4)。但是在10秒之后,它每次都会发出接收内存泄漏警告并崩溃。请看下面的代码相同,我在任何情况下都是错的。

此函数以1秒的间隔与NStimer一起调用。

NSTimer *movementTimer=[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(changingSmiles) userInfo:nil repeats:YES];

-(void)changingSmiles{

 [recorder updateMeters];
const double ALPHA = 0.05;
float lowPassResults=0.0;
double peakPowerForChannel = pow(10, (0.05 * [recorder peakPowerForChannel:0]));
lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults;
float voiceLevel =  [recorder peakPowerForChannel:0];
[voiceNotesArray addObject:[NSString stringWithFormat:@"%f",voiceLevel]];
if(lowPassResults>0.0){
    if (lowPassResults<=0.002018) {

        smileView.image = [smileArr objectAtIndex:2];
        UIImage *image = [self mergeImage:imagefirst:centerView.image:thirdImage];
        [self.imagesArray addObject:image];
    }
    }
 }

下面的函数用于合并发生内存泄漏的应用程序,并且应用程序每次都崩溃。

- (UIImage*)mergeImage:(UIImage *)first:(UIImage *)second:(UIImage *)third
{

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


referenceView.frame = CGRectMake(0, 0, 1024, 768);
referenceView.hidden = NO;

[self.view insertSubview:referenceView belowSubview:selfView];

imgView1.image = first;
imgView2.image = baseview.image;
imgView3.image = second;
imgView4.image = third;

imgView1.frame = selfView.frame;
imgView2.frame = self.view.bounds;
imgView3.frame = centerView.frame;
imgView4.frame = smileView.frame;

[referenceView addSubview:imgView1];
[referenceView addSubview:imgView2];
[referenceView addSubview:imgView3];
[referenceView addSubview:imgView4];

UIImage *finalImage = nil;
UIGraphicsBeginImageContext(referenceView.bounds.size);
[referenceView.layer renderInContext:UIGraphicsGetCurrentContext()];
finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

[referenceView removeFromSuperview];

[imgView1 removeFromSuperview];
[imgView2 removeFromSuperview];
[imgView3 removeFromSuperview];
[imgView4 removeFromSuperview];

//CGImageRelease(finalImage.CGImage);

return finalImage;
[pool drain];
 }

请你帮我解决这个问题。我正在使用ARC项目,但对于此文件,我已禁用ARC并使其成为非ARC。请帮我。

提前致谢。

0 个答案:

没有答案