0

我正在使用 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。请帮我。

提前致谢。

4

0 回答 0