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; |