Releasing Objects in Objective-C Blocks

When using an Objective-C object that returns asynchronously with a completion handler, such as AVAssetExportSession, there is something like wronmg with this code:

AVAssetExportSession* exportSession = [[AVAssetExportSession alloc] initWithAsset: composition presetName: AVAssetExportPresetHighestQuality];
[exportSession exportAsynchronouslyWithCompletionHandler: ^(void) {
    // export completed
    NSLog(@"Export Complete %d %@", exportSession.status, exportSession.error);
    [exportSession release];
    }];

Applies exportSession reports as a leak. I also have several classes of my own that use the same methodology, and they are also reported as leaks.

From everything I read, it looks like the code should follow the memory management rule, but something should be. I found a link to in this article , but I don’t think I am causing a circular save.

+3
source share
1 answer

Objective-C , . exportSession , exportSession .

, , . , , , exportAsynchronouslyWithCompletionHandler:.

AVAssetExportSession* exportSession = [[AVAssetExportSession alloc] initWithAsset: composition presetName: AVAssetExportPresetHighestQuality];
[exportSession exportAsynchronouslyWithCompletionHandler: ^(void) {
    // export completed
    NSLog(@"Export Complete %d %@", exportSession.status, exportSession.error);
}];
[exportSession release];

: exportSession , .

, .

+6

Source: https://habr.com/ru/post/1764430/


All Articles