zoukankan      html  css  js  c++  java
  • __null_unspecified属性关键字解决内存泄漏

    Analyze静态分析时,经常遇到以下内存泄漏

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

    原代码示例

    @property (nonatomic, strong) UIViewController * liveVC;

    - (UIViewController *)liveVC

    {

        UINavigationController * aNav = [UIViewController currentTabbarController].selectedViewController;

        for (UIViewController * aVC in aNav.childViewControllers ) {

            if  ([NSStringFromClass(aVC.class) isEqual:@"HZSMeetingOnlineLiveViewController"]) {

                return aVC;

            }

        }

        return nil;

    }

    解决方式

    @property (nonatomic, strong, null_unspecified) UIViewController * liveVC;

    原代码示例

    - (HZSSameLiveUserModel *)getLiveUserModelWithUserId:(NSString *)userId;

    - (HZSSameLiveUserModel *)getLiveUserModelWithUserId:(NSString *)userId//根据用户id获取模型

    {

        HZSSameLiveUserModel * aSelectModel;

        for (HZSSameLiveUserModel * aModel in HZSLiveInstance.shareInstance.mLiveWindowList) {

            if ([aModel.selectUserId isEqual:userId]) {

                aSelectModel = aModel;

                break;

            }

        }

        return aSelectModel;

    }

    解决方式

    - (null_unspecified HZSSameLiveUserModel *)getLiveUserModelWithUserId:(NSString *)userId;

  • 相关阅读:
    CDN缓存
    nginx作用
    Linux下4个查找命令which、whereis、locate、find
    @ModelAttribute的用法,与@RequestBody的区别
    将kafka消息解析拷贝
    永久代溢出(java.lang.OutOfMemoryError: PermGen space )
    失败重试机制-递归应用1
    kafka-重复消费-2
    读写分离-延时问题-1
    UILabel处理html标签
  • 原文地址:https://www.cnblogs.com/huangzs/p/13520049.html
Copyright © 2011-2022 走看看