Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

会自动调用某些方法 #4

Open
EggmanQi opened this issue Nov 16, 2016 · 2 comments
Open

会自动调用某些方法 #4

EggmanQi opened this issue Nov 16, 2016 · 2 comments

Comments

@EggmanQi
Copy link

背景:
我的项目中所有 VC 都继承于一个 baseVC : UIViewController, baseVC 里面有一个方法叫 loadingHUD。
loadingHUD 是用来显示 MBProgressHUD 的。

现象:
加入 PLeakSniffer 并使用后,发现所有它会自动调用 loadingHUD。
断点得出的路径是:[vc viewDidAppear:] -> [baseVC viewDidAppear:] -> [UIViewController (PLeak) swizzled_viewDidAppear:] -> [NSObject(PLeakTrack) watchAllRetainedProperties:] -> [baseVC loadingHUD]

出需要注意的是,viewDidAppear 并没有处理任何事务。(only [super viewDidAppear:animated];)

莫名其妙。

@wujichao
Copy link

https://github.com/music4kid/PLeakSniffer/blob/master/PLeakSniffer/Classes/NSObject%2BPLeakTrack.m#L56 这里改成下面的代码可以去掉调用getter引来的副作用

     NSString *s = [NSString stringWithFormat:@"_%@", name];
     // 不触发getter
     Ivar nameIVar = class_getInstanceVariable(self.class, [s UTF8String]);
     if (nameIVar) {
         id cur = object_getIvar(self, nameIVar);
     }

@wjiuxing
Copy link

wjiuxing commented Jun 27, 2023

https://github.com/music4kid/PLeakSniffer/blob/master/PLeakSniffer/Classes/NSObject%2BPLeakTrack.m#L56 这里改成下面的代码可以去掉调用getter引来的副作用

     NSString *s = [NSString stringWithFormat:@"_%@", name];
     // 不触发getter
     Ivar nameIVar = class_getInstanceVariable(self.class, [s UTF8String]);
     if (nameIVar) {
         id cur = object_getIvar(self, nameIVar);
     }

发生崩溃在 id cur = object_getIvar(self, nameIVar);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants