无法从静态分析器中找到泄漏
我从 Clang 静态分析器收到一些错误,说我从以下代码中发现了一些泄漏。但是我无法找到泄漏点。请告诉我哪里漏水。
Favourites *fav = [[Favourites alloc] initWithNibName:@"Favourites" bundle:nil];
if (viewController == fav) {
[fav doHud];
[fav release];
}
I am getting some errors from the Clang Static Analyzer saying that I have a few leaks from the following code. However I am unable to find the leak. Please tell me where the leak is.
Favourites *fav = [[Favourites alloc] initWithNibName:@"Favourites" bundle:nil];
if (viewController == fav) {
[fav doHud];
[fav release];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 viewController 没有最终 == 到 fav,则 fav 将不会被释放。您没有将 viewController 设置为等于 fav,因此它不会释放。将
[fav release]
移到if
之外,应该没问题。或者完全摆脱
[favouritesrelease]
并只使用autorelease,例如:Favourites *fav = [[[Favourites alloc] initWithNibName:@"Favourites"bundle:nil] autorelease];< /代码>
fav won't be released if viewController does not end up == to fav. You are not setting viewController to be equal to fav so it won't release. Move
[fav release]
outside theif
and you should be fine.or get rid of the
[fav release]
altogether and just use autorelease like:Favourites *fav = [[[Favourites alloc] initWithNibName:@"Favourites" bundle:nil] autorelease];