iOS常见项目内存泄漏静态分析

Command+Shift+B

1.对一个可变对象使用copy修饰
Property of mutable type 'NSMutableURLRequest' has 'copy' attribute; an immutable object will be stored

@property (readwrite, nonatomic, copy) NSMutableURLRequest *request;

2.没有使用的对象
Value stored to 'color_n' during its initialization is never read

UIColor *color_n = [s_skinDelegate toolbarItemTintColorForState:UIControlStateNormal forModule:kEIPhotoEditor];

3.不应该返回nil
nil returned from a method that is expected to return a non-null value

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = nil;
    
    if (kEIDynamicSection == indexPath.section) {
        EIFrameClassCell* classCell = [collectionView dequeueReusableCellWithReuseIdentifier:kEIFrameClassCellReuseIdentifier forIndexPath:indexPath];
            NSInteger idx = indexPath.item;
        EIFrameClassModel *frameClass = _dataSource[@(kEIDynamicSection)][idx];
        
        if (nil == frameClass.image) {
            EIFrameParam *param = frameClass.param;
            param.thickness = frameClass.sThickness;
            [self.renderUnit asyncRenderWithImage:_image
                                            Param:param
                                         complete:^(UIImage *img, void *info) {
                                             
                                             frameClass.image = img;
                                             NSIndexPath *curCellIndex = [collectionView indexPathForCell:classCell];
                                             if ([curCellIndex isEqual:indexPath]) {
                                                 classCell.image = frameClass.image;
                                             }
                                         }];
        }
        
        classCell.image = (nil == frameClass.image) ? self.image : frameClass.image;
        classCell.isFavorite = frameClass.isFavorite;
        cell = classCell;
    }
    return cell;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return nil;
}

4.将没有返回值转换为指针类型
Result of 'calloc' is converted to a pointer of type 'qn_ips_ret', which is incompatible with sizeof operand type 'char *

qn_ips_ret *ret = calloc(sizeof(char *), ips.count + 1);

5.任务开始时被阻塞
Variable 'task' is uninitialized when captured by block

- (NSURLSessionDownloadTask *)download:(NSString *)URLString
                                    to:(NSString *)dstPath
                               success:(void (^)(NSURLSessionDownloadTask *task, id responseObject))success
                               failure:(void (^)(NSURLSessionDownloadTask *task, NSError *error))failure
                         relateBaseUrl:(BOOL)shouldRelateBaseUrl
                       timeoutInterval:(NSTimeInterval)timeoutInterval
                            retryCount:(NSInteger)retryCount {
    
    NSURL *url = [NSURL URLWithString:URLString relativeToURL:shouldRelateBaseUrl ? self.baseURL : nil];
    NSParameterAssert(url);
    
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager.requestSerializer setTimeoutInterval:timeoutInterval];
    
    NSURLSessionDownloadTask *task = [manager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
        DLog(@"默认下载地址:%@",targetPath);
        return [NSURL fileURLWithPath:dstPath];
    } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
        
        if (!error) {
            if (success) {
                success(task, response);
            }
        }else {
            if (failure) {
                failure(task,error);
            }
        }
    }];
    [task resume];
    return task;
}

6.switch中少写了break
Value stored to 'highQualityImagePixel' is never read

+ (CGFloat)maxPixelSizeGPUSupportedOfThisDevice{
    double highQualityImagePixel = kEIPixel300 ;
    
    UIDevicePlatform platform = [UIDevice currentDevice].devicePlatform;
    
    switch (platform) {
            
        case UIDevice5iPhone:
        case UIDevice5SiPhone:
        case UIDevice6iPhone:
        case UIDevice6PlusiPhone:
            highQualityImagePixel   = kEIPixel800;
            break;
        case UIDevice6SiPhone:
        case UIDevice6SPlusiPhone:
        case UIDevice7iPhone:
        case UIDevice7PlusiPhone:
        case UIDeviceUnknowniPhone:
            highQualityImagePixel   = kEIPixel1200;
            break;
        case UIDevice1GiPadPro:
        case UIDevice2GiPadAir:
        case UIDeviceUnknowniPad:
            highQualityImagePixel = kEIPixel800;
        default: {
            highQualityImagePixel   = kEIPixel500;
            break;
        }
    }
    
    return highQualityImagePixel;
}
  1. viewWillAppear没有继承父类的方法
    The 'viewWillAppear:' instance method in UIViewController subclass 'EINotificationListController' is missing a [super viewWillAppear:] call
-(void)viewWillAppear:(BOOL)animated
{
//    self.navigationController.navigationBar.backgroundColor = RGB(20, 20, 20);
    self.navigationItem.leftBarButtonItem = [AppSkin visionBackIconItemTarget:self action:@selector(cancelTapped)];
}

8.返回的self可能不是配置后的self
Instance variable used while 'self' is not set to the result of '[(super or self) init...]'

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self == [super initWithFrame:frame]) {
        self.opaque = YES;
        
        _canRotate = YES;
        _screenW =  [UIScreen mainScreen].bounds.size.width;
        _screenH =  [UIScreen mainScreen].bounds.size.height;
        
        self.backgroundColor = RGB(36, 36, 36);
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(beginRotate:) name:@"beginRotate" object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endRotate) name:@"endRotate" object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(beginRevertRotate:) name:@"beginRevertRotate" object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endRevertRotate) name:@"endRevertRotate" object:nil];
        
        UITapGestureRecognizer *doubleTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapped:)];
        doubleTapGesture.numberOfTapsRequired = 2;
        
        [self.contentView addGestureRecognizer:doubleTapGesture];
        
        
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapGes)];
        tapGesture.numberOfTapsRequired = 1;
        [tapGesture requireGestureRecognizerToFail:doubleTapGesture];
        [self.contentView addGestureRecognizer:tapGesture];
        
        [self setUpView];
    }
    return self;
}

9.c对象没有释放
Object leaked: object allocated and stored into 'newImageRef' is not referenced later in this execution path and has a retain count of +1

- (UIImage *)imageFromRect:(CGRect)rect
{
    CGImageRef sourceImageRef = [self CGImage];
    CGImageRef newImageRef = CGImageCreateWithImageInRect(sourceImageRef, rect);
    UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
    return newImage;
}

10
Object leaked: object allocated and stored into 'base64' is not referenced later in this execution path and has a retain

+ (NSString *) md5_base64: (NSString *) inPutText
{
    const char *cStr = [inPutText UTF8String];
    unsigned char digest[16];
    CC_MD5( cStr, (int)strlen(cStr), digest );
    
    NSData * base64 = [[NSData alloc]initWithBytes:digest length:16];
    base64 = [GTMBase64 encodeData:base64];
    
    NSString * output = [[NSString alloc] initWithData:base64 encoding:NSUTF8StringEncoding];
    return output;
}

你可能感兴趣的:(iOS常见项目内存泄漏静态分析)