- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在应用商店的应用程序中看到很多崩溃,我完全无法重现或从代码审查中推测可能是什么原因。特别令人困惑的是,这是在应用程序启动时发生的,而内存不足 - 令人困惑是因为如果没有足够的内存供应用程序启动,我可能希望看到其他类型的崩溃报告而不是 EXC_BAD_ACCESS - 即如果 EXC_BAD_ACCESS是由访问已删除的内存引起的,代码中没有任何地方有机会被删除,因为崩溃是在对象正在创建的过程中发生的。
我已经尝试了很多方法来重现这一点——在模拟器中运行并发送低内存警告消息,在应用程序创建过程中故意使各种对象的初始化失败,在应用程序启动期间调用 calloc 以消耗大量内存,运行该应用程序在 RAM 已完全用尽的手机上多次运行。我无法重新创建,也无法从代码检查中看出可能出了什么问题。
这是一个崩溃报告:
Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype:
KERN_INVALID_ADDRESS at 0x0000000000000000 **(many also at 0x0000000000000008)**
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 The_Name_Of_MyApp 0x000000010268ca94 SearchViewController.init(coder:) + 838292 (SearchViewController.swift:67)
1 The_Name_Of_MyApp 0x000000010268ca88 SearchViewController.init(coder:) + 838280 (SearchViewController.swift:67)
2 The_Name_Of_MyApp 0x000000010268cd4c @objc SearchViewController.init(coder:) + 838988 (SearchViewController.swift:0)
3 UIKitCore 0x00000001bca63d64 -[UIClassSwapper initWithCoder:] + 248
4 UIFoundation 0x000000019a77fe88 UINibDecoderDecodeObjectForValue + 744
5 UIFoundation 0x000000019a7800cc UINibDecoderDecodeObjectForValue + 1324
6 UIFoundation 0x000000019a71eb3c -[UINibDecoder decodeObjectForKey:] + 320
7 UIKitCore 0x00000001bd0a1288 -[UIViewController initWithCoder:] + 1420
8 UIKitCore 0x00000001bceb5dcc -[UITabBarController initWithCoder:] + 80
9 The_Name_Of_MyApp 0x000000010283f658 TabBarViewController.init(coder:) + 2618968 (TabBarViewController.swift:0)
10 The_Name_Of_MyApp 0x000000010283f70c @objc TabBarViewController.init(coder:) + 2619148 (TabBarViewController.swift:0)
11 UIKitCore 0x00000001bca63d64 -[UIClassSwapper initWithCoder:] + 248
12 UIFoundation 0x000000019a77fe88 UINibDecoderDecodeObjectForValue + 744
13 UIFoundation 0x000000019a71eb3c -[UINibDecoder decodeObjectForKey:] + 320
14 UIKitCore 0x00000001bcd9dcbc -[UIRuntimeConnection initWithCoder:] + 188
15 UIFoundation 0x000000019a77fe88 UINibDecoderDecodeObjectForValue + 744
16 UIFoundation 0x000000019a7800cc UINibDecoderDecodeObjectForValue + 1324
17 UIFoundation 0x000000019a71eb3c -[UINibDecoder decodeObjectForKey:] + 320
18 UIKitCore 0x00000001bccc4a1c -[UINib instantiateWithOwner:options:] + 1124
19 UIKitCore 0x00000001bce92f18 -[UIStoryboard instantiateViewControllerWithIdentifier:] + 196
20 The_Name_Of_MyApp 0x000000010266b4dc InitialViewController.start() + 701660 (InitialViewController.swift:118)
21 The_Name_Of_MyApp 0x000000010266bba4 @objc InitialViewController.start() + 703396 (InitialViewController.swift:0)
22 Foundation 0x0000000190bff6d0 __NSFireDelayedPerform + 404
23 CoreFoundation 0x00000001900f2bf0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 28
24 CoreFoundation 0x00000001900f2920 __CFRunLoopDoTimer +864
25 CoreFoundation 0x00000001900f2154 __CFRunLoopDoTimers + 248
26 CoreFoundation 0x00000001900ed030 __CFRunLoopRun + 1880
27 CoreFoundation 0x00000001900ec5b8 CFRunLoopRunSpecific + 436
28 GraphicsServices 0x0000000192360584 GSEventRunModal + 100
29 UIKitCore 0x00000001bc9e3558 UIApplicationMain + 212
30 The_Name_Of_MyApp 0x00000001026ea6b0 main + 1222320 (AppDelegate.swift:20)
31 libdyld.dylib 0x000000018fbacb94 start + 4
Thread 1:
0 libsystem_pthread.dylib 0x000000018fd80cfc start_wqthread + 0
Thread 2 name: Dispatch queue: com.myQueue.backgroundSerialQueue
Thread 2:
0 libsystem_c.dylib 0x000000018fc60ae4 __v2printf + 616
1 libsystem_c.dylib 0x000000018fc60a00 __v2printf + 388
2 libsystem_c.dylib 0x000000018fc46ac0 _vsnprintf + 264
3 libsystem_c.dylib 0x000000018fc3b9c0 snprintf_l + 28
4 CoreFoundation 0x000000019010fa88 __CFStringAppendFormatCore + 8548
5 CoreFoundation 0x00000001901111b8 _CFStringCreateWithFormatAndArgumentsAux2 + 136
6 Foundation 0x0000000190afd3ec -[NSString initWithFormat:locale:] + 36
7 Foundation 0x0000000190afd364 -[NSNumber descriptionWithLocale:] + 1044
8 CoreFoundation 0x000000019004d9a8 -[__NSCFNumber descriptionWithLocale:] + 72
9 CoreFoundation 0x0000000190053268 -[__NSCFNumber stringValue] + 64
10 The_Name_Of_MyApp 0x00000001025f6494 -[RobocallerManager readCityAndStateData] + 222356 (RobocallerManager.m:596)
11 The_Name_Of_MyApp 0x00000001025f343c __25-[RobocallerManager init]_block_invoke + 209980 (RobocallerManager.m:148)
12 libdispatch.dylib 0x000000018fb9b6c8 _dispatch_call_block_and_release + 24
13 libdispatch.dylib 0x000000018fb9c484 _dispatch_client_callout + 16
14 libdispatch.dylib 0x000000018fb43c18 _dispatch_lane_serial_drain$VARIANT$mp + 592
15 libdispatch.dylib 0x000000018fb44760 _dispatch_lane_invoke$VARIANT$mp + 432
16 libdispatch.dylib 0x000000018fb4cf00 _dispatch_workloop_worker_thread + 600
17 libsystem_pthread.dylib 0x000000018fd7e0f0 _pthread_wqthread + 312
18 libsystem_pthread.dylib 0x000000018fd80d00 start_wqthread + 4
Thread 3:
0 libsystem_pthread.dylib 0x000000018fd80cfc start_wqthread + 0
Thread 4 name: com.apple.uikit.eventfetch-thread
Thread 4:
0 libsystem_kernel.dylib 0x000000018fceded0 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x000000018fced3a8 mach_msg + 72
2 CoreFoundation 0x00000001900f1fb0 __CFRunLoopServiceMachPort + 236
3 CoreFoundation 0x00000001900ece4c __CFRunLoopRun + 1396
4 CoreFoundation 0x00000001900ec5b8 CFRunLoopRunSpecific + 436
5 Foundation 0x0000000190ae06a4 -[NSRunLoop+ 34468 (NSRunLoop) runMode:beforeDate:] + 300
6 Foundation 0x0000000190ae0514 -[NSRunLoop+ 34068 (NSRunLoop) runUntilDate:] + 88
7 UIKitCore 0x00000001bc940ac0 -[UIEventFetcher threadMain] + 136
8 Foundation 0x0000000190c133b0 __NSThread__start__ + 1040
9 libsystem_pthread.dylib 0x000000018fd7d2fc _pthread_body + 128
10 libsystem_pthread.dylib 0x000000018fd7d25c _pthread_start + 48
11 libsystem_pthread.dylib 0x000000018fd80d08 thread_start + 4
Thread 5 name: com.twitter.crashlytics.ios.MachExceptionServer
Thread 5:
0 libsystem_kernel.dylib 0x000000018fceded0 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x000000018fced3a8 mach_msg + 72
2 The_Name_Of_MyApp 0x000000010288d08c CLSMachExceptionServer + 1180
3 libsystem_pthread.dylib 0x000000018fd7d2fc _pthread_body + 128
4 libsystem_pthread.dylib 0x000000018fd7d25c _pthread_start + 48
5 libsystem_pthread.dylib 0x000000018fd80d08 thread_start + 4
Thread 6:
0 libsystem_pthread.dylib 0x000000018fd80cfc start_wqthread + 0
Thread 7:
0 libsystem_pthread.dylib 0x000000018fd80cfc start_wqthread + 0
Thread 8:
0 libsystem_pthread.dylib 0x000000018fd80cfc start_wqthread + 0
Thread 9:
0 libsystem_pthread.dylib 0x000000018fd80cfc start_wqthread + 0
Thread 10 name: com.apple.NSURLConnectionLoader
Thread 10:
0 libsystem_kernel.dylib 0x000000018fceded0 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x000000018fced3a8 mach_msg + 72
2 CoreFoundation 0x00000001900f1fb0 __CFRunLoopServiceMachPort + 236
3 CoreFoundation 0x00000001900ece4c __CFRunLoopRun + 1396
4 CoreFoundation 0x00000001900ec5b8 CFRunLoopRunSpecific + 436
5 CFNetwork 0x000000019070ce18 -[__CoreSchedulingSetRunnable runForever] + 212
6 Foundation 0x0000000190c133b0 __NSThread__start__ + 1040
7 libsystem_pthread.dylib 0x000000018fd7d2fc _pthread_body + 128
8 libsystem_pthread.dylib 0x000000018fd7d25c _pthread_start + 48
9 libsystem_pthread.dylib 0x000000018fd80d08 thread_start + 4
Thread 0 crashed with ARM Thread State (64-bit):
x0: 0x0000000000000000 x1: 0x0000000000000000 x2: 0x0000000282718580 x3: 0x0000000000000000
x4: 0x0000000104870680 x5: 0x0000000000000000 x6: 0x0000000000000072 x7: 0x00000000000000a0
x8: 0x0000000103f03650 x9: 0x0000000000000000 x10: 0x000000000000001f x11: 0x0000000000000005
x12: 0x0000000000000005 x13: 0x0000000000000000 x14: 0x0000000000000068 x15: 0x00000001ae696425
x16: 0x000000018f34b858 x17: 0x0000000102601328 x18: 0x0000000000000000 x19: 0x0000000104853200
x20: 0x00000001048709c8 x21: 0x0000000280b73880 x22: 0x00000001c92684c0 x23: 0x0000000104870600
x24: 0x0000000281e51ec0 x25: 0x00000001c73e2000 x26: 0x0000000000000002 x27: 0x00000001c73e2000
x28: 0x0000000000000171 fp: 0x000000016d83c0b0 lr: 0x000000010268ca88
sp: 0x000000016d83bcc0 pc: 0x000000010268ca94 cpsr: 0x60000000
下图概述了崩溃报告中显示的对象之间的关系。基本上在应用程序启动时,AppDelegate 会导致 LicenceManger 对象被实例化,这反过来会导致创建 DatabaseManager 和 Database 对象,所有这些都是模型类型类。同时,GUI 正在启动,InitialVC 是一个根 VC,它实例化一个 TabBar VC,这导致 SearchVC 的实例化。SearchVC 访问 DatabaseModel 对象,这就是崩溃发生的地方。
这里是代码(简化为相关部分,注意代码是 Swift 除了 DataBaseManager 是 Ojb-C)
初始 View Controller
////////////////// InitialViewController ////////////////////////////
class InitialViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.perform(#selector(InitialViewController.start), with: nil, afterDelay: 1.5)
}
}
@objc func start() {
let tbvc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "TabBarViewControllerID") as! TabBarViewController
navigationController.pushViewController(tbvc, animated: true)
}
SearchViewController 是由于它与 TabBarViewControllerSp 之间存在关系而创建的
搜索 View Controller
///////////////////////// SearchViewController ///////////////////////////////
class SearchViewController: UITableViewController, UISearchBarDelegate {
var searchResultsList = DatabaseManager.instance().database.emptyList() /** line 67 **/
应用代理
////////////////////// App Delegate ///////////////////////////
AppDelegate:didFinishLaunchingWithOptions() {
let _ = LicenseManager.instance
}
许可证管理器
//////////////////////// LicenseManager ////////////////////////
@objc class LicenseManager : NSObject {
@objc open static let instance = LicenseManager()
private let databaseManager = DatabaseManager.instance()
}
override private init() {
super.init()
}
数据库管理器
///////////////////// DatabaseManager ////////////////////////
+ (DatabaseManager*) instance {
static DatabaseManager *theInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^ {
theInstance = [[DatabaseManager alloc] init];
});
return theInstance;
}
@interface DatabaseManager()
@property (strong, nonatomic) Database* _Nonnull database;
@property (strong, nonatomic) NSMutableDictionary* cityAndStateDictionary;
@end
@implementation DatabaseManager
- (id) init {
self = [super init];
if (self)
{
_database = Database.instance;
[_database openOrCreateDatabase];
dispatch_async(robocallerQueue(), ^{
[self readCityAndStateData];
});
}
return self;
}
//Populates a very large dictionary > 100K entries
- (void) readCityAndStateData
{
NSBundle* bundle = [NSBundle bundleForClass:[DatabaseManager class]];
NSString *filePath = [bundle pathForResource:@"CityState" ofType:@"json"];
NSData *data = [NSData dataWithContentsOfFile:filePath];
Assert(data, @"unable to read CityState.json file");
NSError* __autoreleasing nserror;
NSDictionary* jsonParser = [NSJSONSerialization JSONObjectWithData: data
options: NSJSONReadingAllowFragments
error: &nserror];
if (nserror == nil)
{
self.cityAndStateDictionary = [[NSMutableDictionary alloc] init];
self.stateDictionary = [[NSMutableDictionary alloc] init];
for (NSDictionary *item in jsonParser)
{
NSNumber* num1 = item[@"Code1"];
NSNumber* num2 = item[@"Code2"];
NSString* key = [NSString stringWithFormat:@"%@%@", num1.stringValue, num2.stringValue];
NSString* city = item[@"City"];
NSString* state = item[@"State"];
NSString* value = [NSString stringWithFormat:@"%@, %@", [city capitalizedString], state];
(self.cityAndStateDictionary)[key] = value;
NSString* stateKey = [num1 stringValue];
(self.stateDictionary)[stateKey] = state;
}
self.cityAndStateDataLoaded = TRUE;
}
else
{
Assert(data, @"unable to parse CityState.json file");
}
}
数据库
////////////////////// Database //////////////////////
@objcMembers class Database : NSObject {
open static let instance = Database()
fileprivate var configuration:Realm.Configuration? = nil
override init()
{
}
}
@objc func openOrCreateDatabase() {
configuration = Realm.Configuration(encryptionKey: Database.getKey() as Data)
}
class func getKey() -> NSData {
let string = "AED16D8B-7762-4CBF-A313-48FDCAD51B9C23456754635498123450ka&9dB6t"
let data = string.data(using: String.Encoding.utf8)
return data! as NSData
}
func emptyList() -> Results<Caller> {
let realm = try! Realm(configuration: configuration!)
let mdn = "DoesNotExist"
let searchTerm = "number == " + "\"" + mdn + "\""
let results = realm.objects(Caller.self).filter(searchTerm)
return results
}
来电者
//////////////// Caller ///////////
@objc public class Caller : Object {
@objc dynamic var name:String? = nil
// More simple types, strings, dates, ints etc.
}
最佳答案
这不是强制解包的结果,我猜这是故意的,如果无法创建数据库会故意崩溃。 EXC_BAD_ACCESS KERN_INVALID_ADDRESS
当你有一个僵尸时发生:代码试图访问释放的内存(类似的崩溃消息 here 和 here )。
以下是消除僵尸的一般建议:
罪魁祸首是:DatabaseManager.instance().database.emptyList()
DatabaseManager.instance()
这是首先在 AppDelegate 中通过 let _ = LicenseManager.instance
创建的.由于应用程序在调用 SearchViewController.init(coder:)
时崩溃,而不是在 AppDelegate 中,可以公平地假设创建 DatabaseManager.instance()
, Database.instance
在 AppDelegate 中是无害的。
DatabaseManager.instance().database
这也不是罪魁祸首,如前所述:这是在 AppDelegate 中创建的。
emptyList()
这给我们留下了这个方法。它在主线程中被调用。作为一种方法本身,它会以 KERN_INVALID_ADDRESS
使应用程序崩溃的唯一情况。消息,如果它被发送到僵尸。这意味着 DatabaseManager.instance().database
在主线程中还不存在。这意味着 1.5
InitialViewController
中的第二次延迟不够 robocallerQueue
返回一个非零 DatabaseManager.instance().database
.从崩溃报告可以看到,当主线程(线程0)崩溃时,线程2还在执行readCityAndStateData
.
我建议标记 searchResultsList
懒惰,或使用完成处理程序而不是 1.5 秒延迟。
关于ios - 无法确定 EXC_BAD_ACCESS 的可能原因(在应用程序启动期间发生),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52545141/
我是 C 语言新手,我编写了这个 C 程序,让用户输入一年中的某一天,作为返回,程序将输出月份以及该月的哪一天。该程序运行良好,但我现在想简化该程序。我知道我需要一个循环,但我不知道如何去做。这是程序
我一直在努力找出我的代码有什么问题。这个想法是创建一个小的画图程序,并有红色、绿色、蓝色和清除按钮。我有我能想到的一切让它工作,但无法弄清楚代码有什么问题。程序打开,然后立即关闭。 import ja
我想安装screen,但是接下来我应该做什么? $ brew search screen imgur-screenshot screen
我有一个在服务器端工作的 UDP 套接字应用程序。为了测试服务器端,我编写了一个简单的 python 客户端程序,它发送消息“hello world how are you”。服务器随后应接收消息,将
我有一个 shell 脚本,它运行一个 Python 程序来预处理一些数据,然后运行一个 R 程序来执行一些长时间运行的任务。我正在学习使用 Docker 并且我一直在运行 FROM r-base:l
在 Linux 中。我有一个 c 程序,它读取一个 2048 字节的文本文件作为输入。我想从 Python 脚本启动 c 程序。我希望 Python 脚本将文本字符串作为参数传递给 c 程序,而不是将
对于一个类,我被要求编写一个 VHDL 程序,该程序接受两个整数输入 A 和 B,并用 A+B 替换 A,用 A-B 替换 B。我编写了以下程序和测试平台。它完成了实现和行为语法检查,但它不会模拟。尽
module Algorithm where import System.Random import Data.Maybe import Data.List type Atom = String ty
我想找到两个以上数字的最小公倍数 求给定N个数的最小公倍数的C++程序 最佳答案 int lcm(int a, int b) { return (a/gcd(a,b))*b; } 对于gcd,请查看
这个程序有错误。谁能解决这个问题? Error is :TempRecord already defines a member called 'this' with the same paramete
当我运行下面的程序时,我在 str1 和 str2 中得到了垃圾值。所以 #include #include #include using namespace std; int main() {
这是我的作业: 一对刚出生的兔子(一公一母)被放在田里。兔子在一个月大时可以交配,因此在第二个月的月底,每对兔子都会生出两对新兔子,然后死去。 注:在第0个月,有0对兔子。第 1 个月,有 1 对兔子
我编写了一个程序,通过对字母使用 switch 命令将十进制字符串转换为十六进制,但是如果我使用 char,该程序无法正常工作!没有 switch 我无法处理 9 以上的数字。我希望你能理解我,因为我
我是 C++ 新手(虽然我有一些 C 语言经验)和 MySQL,我正在尝试制作一个从 MySQL 读取数据库的程序,我一直在关注这个 tutorial但当我尝试“构建”解决方案时出现错误。 (我正在使
仍然是一个初学者,只是尝试使用 swift 中的一些基本函数。 有人能告诉我这段代码有什么问题吗? import UIKit var guessInt: Int var randomNum = arc
我正在用 C++11 编写一个函数,它采用 constant1 + constant2 形式的表达式并将它们折叠起来。 constant1 和 constant2 存储在 std::string 中,
我用 C++ 编写了这段代码,使用运算符重载对 2 个矩阵进行加法和乘法运算。当我执行代码时,它会在第 57 行和第 59 行产生错误,非法结构操作(两行都出现相同的错误)。请解释我的错误。提前致谢:
我是 C++ 的初学者,我想编写一个简单的程序来交换字符串中的两个字符。 例如;我们输入这个字符串:“EXAMPLE”,我们给它交换这两个字符:“E”和“A”,输出应该类似于“AXEMPLA”。 我在
我需要以下代码的帮助: 声明 3 个 double 类型变量,每个代表三角形的三个边中的一个。 提示用户为第一面输入一个值,然后 将用户的输入设置为您创建的代表三角形第一条边的变量。 将最后 2 个步
我是新来的,如果问题不好请见谅 任务:将给定矩阵旋转180度 输入: 1 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 输出: 16 15 14 13 12 11
我是一名优秀的程序员,十分优秀!