静态分析:不需要运行项目直接可以预测分析问题。
静态分析比较常见的一些问题如下:
Showing Recent Issues
1、Value stored to 'x' during its initialization is never read.(这种属于dead store)
这种情况就是创建了对象&&初始化了该对象,但是没有使用。这是内存泄漏。
2、Property of mutable type 'NSMutableDictionary' has 'copy' attribute; an immutable object will be stored instead.(这种归为logic error)
NSmutableDictionary对象用copy修饰,所以最后它会被赋予一个不可变对象。
How to resolve this issue ?
Change the 'copy' attribute to 'strong' .
3、leak of an object stored into 'path'.
Call to function 'CGPathCreateMutable' returns a Core Foundation object of type CGMutablePathRef _Nonnull with a +1 retain count.
Object leaked: object allocated and stored into 'path' is not referenced later in this execution path and has a retain count of +1.
出现这个问题的源码是这样的:
#pragma mark - 最原始的绘图方式
- (void)drawLine
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 50, 50);
CGPathAddLineToPoint(path, NULL, 200, 200);
CGContextAddPath(ctx, path);
CGContextStrokePath(ctx);
//CGPathRelease(path);//缺少这句代码就会出现内存泄漏问题。C语言创建的对象需要手动释放。
}
4、Null passed to a callee that requires a non-null 2nd parameter.(这个归为memory error)
意思就是说,咱不是说好了调用函数的时候参数不能为空吗,你传个null来干啥子哟。找抽啊。
好咯,怪我咯
How to resolve issue ?
我就只能想办法让传入参数的变量不为空咯,我确保它不为空行了吧。