1、使用了定时器,NSTimer没有销毁
- (void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
if (self.timer) {
[_timer invalidate];
_timer = nil;
}
}
2、delegate属性使用weak、asign修饰符
3、block使用注意使用弱引用,避免强引用
#define WeakSelf(weakSelf) __weak __typeof(&*self)weakSelf = self;
#define StrongSelf(strongSelf) __strong __typeof(&*self)strongSelf = weakSelf;
4、注册与JS交互时把self传给了MessageHandler
[self.webView.configuration.userContentController addScriptMessageHandler:self name:@"getStorage"];
所以需要在页面关闭时移除js交互对象,可以在viewDidDisappear中移除
[self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"getStorage"];
5、我遇到的小坑,特殊情况
因为是创建了一个manager继承NSObject,专门来管理webView,并且在需要使用网页的控制器中把self传入了这个manager,当时我在manager中是这样声明对象的
@property (nonatomic, Strong) BaseViewController *controller;
很明显这和上面说到的是一个道理,controller强引用manager,manager强引用controller,所以循环引用了,这些需要改成weak申明
@property (nonatomic, weak) BaseViewController *controller;
网友评论