gpt4 book ai didi

ios - 调用 [super dealloc] 和调用父类(super class)方法实现的区别

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:43:16 25 4
gpt4 key购买 nike

调用 [super dealloc] 和从父类(super class)获取 IMP 并调用它有什么区别?

Method deallocMethod = class_getInstanceMethod([self superclass], @selector(dealloc));
IMP superImp = method_getImplementation(deallocMethod);
((void (*)(id, SEL))superImp)(self, _cmd);

根据我使用的内容,我会得到两种不同的行为。我在 UIViewController 的动态子类中看到了这种不同的行为。

编辑:

详细说明。我没有使用 ARC。

行为上的差异也很难描述,但我会尽力而为。似乎 UIViewController 在 dealloc 中所做的一些清理工作没有完成。如果我只调用 [super dealloc] 我会收到一条消息,该消息将发送到 View Controller 的已释放实例。当它在 UIViewController (+[UIViewController setViewController:forView:]) 的静态函数中为 View (我不完全理解的内部的东西)增长 View Controller 的散列时,会发生这种情况。我的猜测是,在我只调用 [super dealloc] 的情况下, View Controller 不会从哈希中删除。

最佳答案

你不要在 ARC 中调用 [super dealloc]。否则两者相同。

关于ios - 调用 [super dealloc] 和调用父类(super class)方法实现的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16406983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com