在这件事上遇到了困难,希望有人能帮上忙!新发布,但发现这是我的网站,帮助我通过我的应用程序。
我有一个应用程序,它使用writeImageToSavedPhotosAlbum:orientation:completionBlock:.将一个CGImage复制到照片库功能上很好,但仪器似乎在告诉我我有漏洞。通过尝试和错误以及对代码的注释,我发现这个特定的行导致了泄漏:
[library writeImageToSavedPhotosAlbum:myCGImage
orientation:assetOrientation
completionBlock:^(NSURL *assetURL, NSError *error){
NSLog(@"image copied to album");
}];这句话对我来说是无害的,所以我真的不知道它为什么会引起问题。评论,没有泄漏。把它留在里面,我看到漏水了!
下面是仪器在泄露的块中显示的内容:
Leaked Object # Address Size Responsible Library Responsible Frame
GeneralBlock-36864, 0x8c77000 36.00 KB MusicLibrary MemNewPtrClear下面是来自仪器的堆栈跟踪,这似乎意味着它确实与照片库有关:
0 libsystem_c.dylib calloc
1 MusicLibrary MemNewPtrClear
2 MusicLibrary ReadITImageDB
3 MusicLibrary -[MLPhotoLibrary _loadImageLibrary]
4 MusicLibrary -[MLPhotoLibrary albums]
5 PhotoLibrary -[PLPhotoLibrary albums]
6 PhotoLibrary -[PLPhotoLibrary eventAlbumContainingPhoto:]
7 PhotoLibrary -[PLPhotoLibrary pictureWasTakenOrChanged]
8 PhotoLibrary __-[PLAssetsSaver queueJobData:requestEnqueuedBlock:completionBlock:imagePort:previewImagePort:]_block_invoke_2
9 libdispatch.dylib _dispatch_call_block_and_release
10 libdispatch.dylib _dispatch_main_queue_callback_4CF$VARIANT$up
11 CoreFoundation __CFRunLoopRun
12 CoreFoundation CFRunLoopRunSpecific
13 CoreFoundation CFRunLoopRunInMode
14 GraphicsServices GSEventRunModal
15 GraphicsServices GSEventRun
16 UIKit -[UIApplication _run]
17 UIKit UIApplicationMain
18 mogofoto main /Users/Jutsu/Documents/mogofoto2/main.m:14
19 mogofoto start我确实在稍后发布了myCGIImage,也发布了库,而assetOrientation只是一个ALAssetOrientation。没有什么是自定义代码,所以我很困惑!(如果这可能导致问题的话,我很乐意发布我的其他代码行)。
任何帮助都是非常感谢的!
发布于 2011-07-24 11:28:43
我有和你相似的密码:
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
NSMutableDictionary *metadata = [[NSMutableDictionary alloc] init];
/* ... set up the metadata */
[library writeImageToSavedPhotosAlbum:image.CGImage metadata:metadata
completionBlock:^(NSURL *assetURL, NSError *error)
{ NSLog(@"assetURL %@", assetURL);
[metadata release];
[library release];
}
];我看到了和你完全一样的泄密:
Leaked Object Address Size Responsible Library Responsible Frame
GeneralBlock-36864,0x5066000 36.00 KB MusicLibrary MemNewPtrClear
GeneralBlock-36864,0x4fd3000 36.00 KB MusicLibrary MemNewPtrClear
GeneralBlock-36864,0x4f72000 36.00 KB MusicLibrary MemNewPtrClear
GeneralBlock-36864,0x45ce000 36.00 KB MusicLibrary MemNewPtrClear有一个堆栈:
0 libsystem_c.dylib calloc
1 MusicLibrary MemNewPtrClear
2 MusicLibrary ReadITImageDB
3 MusicLibrary -[MLPhotoLibrary _loadImageLibrary]
4 MusicLibrary -[MLPhotoLibrary albums]
5 PhotoLibrary -[PLPhotoLibrary albums]
6 PhotoLibrary -[PLPhotoLibrary eventAlbumContainingPhoto:]
7 PhotoLibrary -[PLPhotoLibrary pictureWasTakenOrChanged]
8 PhotoLibrary __-[PLAssetsSaver queueJobData:requestEnqueuedBlock:completionBlock:imagePort:previewImagePort:]_block_invoke_2
9 libdispatch.dylib _dispatch_call_block_and_release
10 libdispatch.dylib _dispatch_main_queue_callback_4CF$VARIANT$up
11 CoreFoundation __CFRunLoopRun
12 CoreFoundation CFRunLoopRunSpecific
13 CoreFoundation CFRunLoopRunInMode
14 GraphicsServices GSEventRunModal
15 GraphicsServices GSEventRun
16 UIKit -[UIApplication _run]
17 UIKit UIApplicationMain
18 myAppName main
19 myAppName start我看不出代码有什么问题,但再看一遍,每次我想要写映像时,分配ALAssetsLibrary和NSMutableDictionary似乎都很愚蠢。我重新编写了代码来保存它们,并从完成块中删除了发布调用,泄漏神奇地消失了。
我不确定这些是否真的对你有很大帮助。但这确实让我怀疑,苹果的代码是否真的有问题,只有在某些情况下才会触发--当然,我没有看到我正在写的每一张图片都有漏洞,只有其中一些。
https://stackoverflow.com/questions/6742351
复制相似问题