iosobjective-cmemory-leaksalassetassetslibrary

Leaked Objects: ALasset and ALAssetPrivate


I am using Profile to find any memory leaks.

I found 2 interesting leaks, which i can't understand:

Leaked Object |  Responsible Library | Responsible Frame

ALAsset         AssetsLibrary         [ALAssetsGroup _enumerateAssetsAtIndexes:options:usingBlock:]_block_invoke_0125

ALAssetPrivate  AssetsLibrary        -[ALAsset initWithManagedAsset:library:]

Is is my problem or AssetsLibrary? Are there any ideas how to fix this?


Solution

  • The problem lies in the Asset library itself. It contains a memory leak. Evidence is that the following code already shows a leak in the profiler (notice that I commented out the line where I added the asset to a mutable array):

    [assetGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {         
            if(result == nil) {
                *stop = YES;
            } else {
                //[theAssets addObject:result];
            }
    }];
    

    A possible fix would be to check the retain count of the ALAsset pointer and release it yourself an extra time if the retain count is > 1 (it should be 1 at the end of the block if you have not retained it yourself).

    EDIT:

    I noticed the leak is actually an ALAssetPrivate object which is over-retained by ALAsset, the retain count of the ALAsset instance is correct.

    EDIT:

    Stupid me, the memory leak was actually caused by a category I implemented on ALAsset which included a dealloc method of itself. This was the cause of the leak.