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;

  • 相关阅读:
    os 模块删除图片操作
    python base64基本使用
    django 跨域
    git 回滚
    多线程
    原生sql子查询 和psql 子查询
    Python 3.x 中"HTTP Error 403: Forbidden"问题的解决方案
    报错(AttributeError: 'str' object has no attribute 'items')的解决办法
    C++虚函数
    C++泛型程序设计和多态
  • 原文地址:https://www.cnblogs.com/huangzs/p/13520049.html
Copyright © 2011-2022 走看看