简体   繁体   English

Clang静态分析仪足够吗?

[英]Is Clang Static Analyzer enough?

I'm new to iphone and objective-c development and want to ask if Clang Static Analyzer is enough for getting rid of memory leaks? 我是iphone和objective-c开发的新手,想问一下Clang Static Analyzer是否足以摆脱内存泄漏? I personally found the xcode "Leaks" tool rather difficult to use, besides I've seen some articles, where it reads that it will always show memory leaks, even if there are no any real leaks. 我个人发现xcode“Leaks”工具相当难以使​​用,除了我看过一些文章,它会读到它总会显示内存泄漏,即使没有任何真正的泄漏。

If I don't have any warnings from clang analyzer, does it mean that I don't have any memory leaks? 如果我没有来自clang分析器的任何警告,是否意味着我没有任何内存泄漏? Or I need to check it somehow else? 或者我需要以其他方式检查它?

What do you think? 你怎么看? Thank you very much. 非常感谢你。

No it is not. 不它不是。 CSA is a static analysis tool, meaning it can only catch things that can be reasoned about at compile time. CSA是一个静态分析工具,意味着它只能捕获编译时可以推理的内容。 To that end it also isn't perfect, far from it. 为此,它还不完美,远非如此。 It is definitely no substitute for Instruments. 它绝对不能替代仪器。 CSA can however, help remind you of things in the rules, and other potential problems. 但是,CSA可以帮助提醒您规则中的内容以及其他潜在问题。

If you are using the built in Build and Analyze, you can get better results by downloading the real scan-build and turning on all checks 如果您使用内置的Build and Analyze,则可以通过下载真实的扫描构建并打开所有检查来获得更好的结果

http://www.loufranco.com/blog/files/scan-build-better-than-build-analyze.html http://www.loufranco.com/blog/files/scan-build-better-than-build-analyze.html

But, it's still not enough. 但是,它仍然不够。 You need to check for leaks using run-time analysis. 您需要使用运行时分析来检查泄漏。 If you keep to very simple alloc/retain/release rules, you might be able to get away with it (or so close, that the Leaks tool becomes much easier to deal with). 如果您遵循非常简单的alloc / retain / release规则,您可能可以使用它(或者如此接近,Leaks工具变得更容易处理)。

No, the static analyser is one of the tools that is handy to have but you shouldn't rely solely on it. 不,静态分析仪是方便的工具之一,但你不应该单独依赖它。

Instruments and in particular the Leaks and Memory allocation tools are great ways to find leaks. 仪器,特别是泄漏和内存分配工具是查找泄漏的好方法。 The memory allocation tool can help you find leaks that leaks can't because it can show you the overall memory usage, if you notice it going up but never coming down after you finish a task you can start looking for a possible leak... 内存分配工具可以帮助您找到泄漏不能泄漏,因为它可以显示整体内存使用情况,如果您注意到它上升但是在完成任务后永远不会崩溃,您可以开始寻找可能的泄漏......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM