2012-05-16 1 views
0

해제하고 난 줄에서 메모리 누수를 얻고 방법 :내가 다음과 같은 코드를 작성 AVASSETEXPORTSESSION 아이폰 OS

AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetPassthrough]; 

내 코드는 다음과 같습니다

NSError *error; 
AVMutableComposition* mixComposition = [AVMutableComposition composition]; 


NSURL* audio_inputFileUrl = [_songPath valueForProperty:MPMediaItemPropertyAssetURL]; 

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; 

NSString *video_inputFilePath = [documentsDirectory stringByAppendingPathComponent:@"videoOutput1234videoOutput1234.mp4"]; 
NSLog(@"output url %@",video_inputFilePath); 

NSURL* video_inputFileUrl = [NSURL fileURLWithPath:video_inputFilePath]; 


NSArray *docPaths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *docPath=[docPaths objectAtIndex:0]; 
NSString* outputFilePath = [docPath stringByAppendingPathComponent:@"OutPut.mov"];//[[NSBundle mainBundle] pathForResource:@"OutPut" ofType:@"mov"]; 
NSURL* outputFileUrl = [NSURL fileURLWithPath:outputFilePath]; 

if ([[NSFileManager defaultManager] fileExistsAtPath:outputFilePath]) 
{ 
    [[NSFileManager defaultManager] removeItemAtPath:outputFilePath error:nil]; 
} 
else { 
    NSString *defaultPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"OutPut.mov"]; 
    [[NSFileManager defaultManager] copyItemAtPath:defaultPath toPath:outputFilePath error:&error]; 
    [[NSFileManager defaultManager] removeItemAtPath:outputFilePath error:nil]; 
} 



CMTime nextClipStartTime = kCMTimeZero; 

AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:video_inputFileUrl options:nil]; 
CMTimeRange video_timeRange = CMTimeRangeMake(kCMTimeZero,videoAsset.duration); 
AVMutableCompositionTrack *a_compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; 

[a_compositionVideoTrack insertTimeRange:video_timeRange ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:nextClipStartTime error:nil]; 


AVURLAsset* audioAsset = [[AVURLAsset alloc]initWithURL:audio_inputFileUrl options:nil]; 
CMTimeRange audio_timeRange = CMTimeRangeMake(kCMTimeZero, audioAsset.duration); 
AVMutableCompositionTrack *b_compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; 
[b_compositionAudioTrack insertTimeRange:audio_timeRange ofTrack:[[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:nextClipStartTime error:nil]; 
if ([[NSFileManager defaultManager] fileExistsAtPath:outputFilePath]) 
    [[NSFileManager defaultManager] removeItemAtPath:outputFilePath error:nil]; 

AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetPassthrough]; 
_assetExport.outputFileType = @"com.apple.quicktime-movie"; 
_assetExport.outputURL = outputFileUrl; 

if ([[NSFileManager defaultManager] fileExistsAtPath:outputFilePath]) 
    [[NSFileManager defaultManager] removeItemAtPath:outputFilePath error:nil]; 

[_assetExport exportAsynchronouslyWithCompletionHandler:^(void) {[self saveVideoToAlbum:outputFilePath]; }  ];  

[outputFileUrl release]; 
[videoAsset release]; 
[audioAsset release]; 
if (_assetExport.status == 2) { 
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Exporting to library is completed" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK",nil]; 
    [alertView show]; 
    [alertView release]; 
    [mixComposition release]; 
} 

내가 AVASSETEXPORTSESSION를 해제하려고 할 때 내 응용 프로그램이 충돌하고 나는이 아이디어를 어떻게 풀어 낼지 모른다.

나에게 답을 말해 줄 수 있니?

답변

0

당신은 해제 할 필요가 없습니다 :

[outputFileUrl release]; 
[mixComposition release]; 

당신의 코드에서 다음 줄을 제거합니다. 자신이 소유하고 있지 않기 때문에 (할당되지 않음) 그렇게해야합니다. 따라서 을 배포 할 필요가 없습니다.

그리고 이제 작동합니다.

오토 릴리즈 :

AVAssetExportSession* _assetExport = [[[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetPassthrough] autorelease]; 

또는 릴리스 :

[_assetExport release];