Analyze检测内存泄露常遇问题

2019-05-09  本文已影响0人  尼古拉斯超仔

最近在做内存泄露检测,记录一下遇到的问题,欢迎大家补充 🙂

1.instance variable used while 'self' is not set to the result of '[(super or self) init...]

//提示错误
-(instancetype)initWithType:(FTFFavorateType)type
{
    if (self == [super init]) {
        _type = type;
    }
    return self;
}
//修改为如下
- (instancetype)initWithType:(FTFFavorateType)type
{
    if (self = [super init]) {
        _type = type;
    }
    return self;
}

2.Value stored to ‘durationValue’ during its initialization is never read(在初始化过程中存储的“持续时间值”的值永远不会被读取)

// 此段代码提示错误
NSMutableArray *datesArray = [[NSMutableArray alloc] init];
datesArray = [_onDemandDictionary objectForKey:key];
//修改为如下
NSMutableArray *datesArray = nil;
datesArray = [_onDemandDictionary objectForKey:key];

3.User-facing text should use localized string macro

4.nil returned from a method that is expected to return a non-null value

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell;
return cell;
}
//修改为
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
arort();
}

5.Potential leak of an object stored into 'xxx'

6.the left operand of ** is a garbage value

 CGPoint point;
 float height = point.y + 5.0;
//修改为
CGPoint point = CGPointZero;
float height = point.y + 5.0;

7.value stored to is never read

8.Property of mutable type 'NSMutableString' has 'copy' attribute; an immutable object will be stored instead

@property (nonatomic,copy) NSMutableString *str;
//修改为
@property (nonatomic,strong) NSMutableString *str;
上一篇下一篇

猜你喜欢

热点阅读