不理解“对象可能泄漏”错误
346 - NSFileManager *fileManager = [[NSFileManager alloc] init];
347 - [fileManager removeItemAtPath:[mediaSource.newMediaToDelete objectAtIndex:i] error:nil];
348 - [fileManager release];
错误指向第 348 行并表示:
“第 347 行分配的对象存在潜在泄漏”
我不明白这一点,显然第 347 行不是分配,并且第 346 行的分配已经释放。
346 - NSFileManager *fileManager = [[NSFileManager alloc] init];
347 - [fileManager removeItemAtPath:[mediaSource.newMediaToDelete objectAtIndex:i] error:nil];
348 - [fileManager release];
The error points towards line 348 and says:
'Potential leak of an object allocated on line 347'
I don't understand this, obviously line 347 isn't an allocation, and the allocation on line 346 is already released.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
避免在您自己的方法名称中使用“new”或“create”(除非它们返回我猜不是自动释放的对象)。它使静态分析器感到困惑。我遇到过这个问题,并发现当我更改方法名称时它就消失了。
更新:我看到 Bvarious 已经在评论中注意到了这一点。
Avoid using the 'new' or 'create' in your own method names (unless they return objects that are not autoreleased I guess). It confuses the static analyser. I've had this issue and found it went away when I changed my method name.
Update: I see Bavarious has already noted this in the comments.
可能 NSArray mediaSource.newMediaToDelete 对象不是自动释放的?
May be in NSArray mediaSource.newMediaToDelete objects are not autorelease?
我尝试了以下代码,但没有收到任何警告:
所以它必须与返回的 mediaSource.newMediaToDelete 对象一起...
尝试 var allocateemnt 像:
它应该显示在那里...
I tried the following code and did not get any warning:
So it must be with returned mediaSource.newMediaToDelete object...
try a var assignemnt like:
and it should show there...
您是否尝试过单击错误消息本身?这些向您显示问题路径的箭头有时非常有用。我猜想是 mediaSource 或 newmediaToDelete 对象导致了该消息。
Have you tried to click on the error message itself? Those arrows which show you the path of your problem are sometimes very useful. I guess it is the mediaSource or newmediaToDelete object which causes the message.