lixiang1994 / LEETheme

优雅的主题管理库- 一行代码完成多样式切换
MIT License
820 stars 135 forks source link

[self lee_theme_dealloc] EXC_BAD_ACCESS crash #27

Open jerrywangjing opened 2 years ago

jerrywangjing commented 2 years ago

在APP从后台切换到前台时,可能会造成app crash,通过异常断点查看,崩溃到的[self lee_theme_dealloc];这里,不太理解作者为什么在这里要多次递归调用该方法,可能引起crash的原因就是self(LEETheme)对象过度内存释放导致的,希望作者能修复该问题。谢谢。

下面是出现crash的文件,及代码片段:

文件:#import "LEETheme.h"

...

@implementation NSObject (LEEThemeConfigObject)
...

- (void)lee_theme_dealloc{

    if ([self isLeeTheme]) {

        [[NSNotificationCenter defaultCenter] removeObserver:self name:LEEThemeChangingNotificaiton object:nil];

        objc_removeAssociatedObjects(self);
    }
    [self lee_theme_dealloc];  // 注:crash 在这里
}
lixiang1994 commented 2 years ago

实际上是交换了方法实现的, 并不是递归调用, [self lee_theme_dealloc]; 调用的是原来的方法实现, 崩溃到这里并不是由 LEETheme引起的.

Sunshineyg00 commented 2 months ago

实际上是交换了方法实现的, 并不是递归调用, [self lee_theme_dealloc]; 调用的是原来的方法实现, 崩溃到这里并不是由 LEETheme引起的.

我们的app近来也发生多次这样的crash了,貌似比较多是在iOS 17.6.1 原因是:EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x00000000ffffffff 堆栈如下: 0 libobjc.A.dylib objc_release_x8 + 8 1 Network __33-[NWConcrete_nw_endpoint dealloc]_block_invoke_2 + 52 2 Network -[NWConcrete_nw_endpoint dealloc] + 544 3 Network -[NWConcrete_nw_address_endpoint dealloc] + 76 4 Network -[OS_nw_array dealloc] + 284 5 Network -[NWConcrete_nw_path .cxx_destruct] + 92 6 libobjc.A.dylib object_cxxDestructFromClass(objc_object, objc_class) + 116 7 libobjc.A.dylib objc_destructInstance + 80 8 libobjc.A.dylib _objc_rootDealloc + 80 9 myapp LEETheme.m - 第 1985 行 -[NSObject(LEEThemeConfigObject) lee_theme_dealloc] + 1985 10 Network -[NWConcrete_nw_path dealloc] + 100 11 Network -[NWConcrete_nw_path_evaluator .cxx_destruct] + 68 12 libobjc.A.dylib object_cxxDestructFromClass(objc_object, objc_class) + 116 13 libobjc.A.dylib objc_destructInstance + 80 14 libobjc.A.dylib _objc_rootDealloc + 80 15 myapp LEETheme.m - 第 1985 行 -[NSObject(LEEThemeConfigObject) lee_theme_dealloc] + 1985 16 Network -[NWConcrete_nw_path_evaluator dealloc] + 280 17 Network nw_nat64_v4_address_requires_synthesis + 388 18 libsystem_info.dylib _gai_nat64_second_pass + 280 19 libsystem_info.dylib si_addrinfo + 1348 20 libsystem_info.dylib getaddrinfo + 168

lixiang1994 commented 2 months ago

任何NSObject 在dealloc发生crash, 堆栈里都会有-[NSObject(LEEThemeConfigObject) lee_theme_dealloc], 你即使把LEETheme移除, crash也不会消失.