不理解“对象可能泄漏”错误

发布于 2024-12-03 15:32:00 字数 343 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

老子叫无熙 2024-12-10 15:32:00

避免在您自己的方法名称中使用“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.

白色秋天 2024-12-10 15:32:00

可能 NSArray mediaSource.newMediaToDelete 对象不是自动释放的?

May be in NSArray mediaSource.newMediaToDelete objects are not autorelease?

凉城已无爱 2024-12-10 15:32:00

我尝试了以下代码,但没有收到任何警告:

  NSInteger i = 0;
    NSArray *ax = [NSArray arrayWithObjects:@"a",@"b",@"c",nil];
    NSFileManager *fileManager = [[NSFileManager alloc] init];
    [fileManager removeItemAtPath:[ax objectAtIndex:i] error:nil];
    [fileManager release];

所以它必须与返回的 mediaSource.newMediaToDelete 对象一起...

尝试 var allocateemnt 像:

x = [mediaSource.newMediaToDelete objectAtIndex:i];

它应该显示在那里...

I tried the following code and did not get any warning:

  NSInteger i = 0;
    NSArray *ax = [NSArray arrayWithObjects:@"a",@"b",@"c",nil];
    NSFileManager *fileManager = [[NSFileManager alloc] init];
    [fileManager removeItemAtPath:[ax objectAtIndex:i] error:nil];
    [fileManager release];

So it must be with returned mediaSource.newMediaToDelete object...

try a var assignemnt like:

x = [mediaSource.newMediaToDelete objectAtIndex:i];

and it should show there...

怪异←思 2024-12-10 15:32:00

您是否尝试过单击错误消息本身?这些向您显示问题路径的箭头有时非常有用。我猜想是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文