我有以下代码:
- (Item *) getRandomItem {
if (itemIDs == nil) {
[self parse];
}
NSArray * allKeys = [allItems allKeys];
int seed = arc4random()%[allKeys count];
return [self getItemByID:[allKeys objectAtIndex:seed]];
}
它有时会在实时应用程序上崩溃,但我们无法重现崩溃。我一直在尝试分析报告并了解崩溃的可能原因,但我没有成功。我尝试以任何方式篡改 allItems 对象以产生崩溃,结果导致与此处报告的错误不同的错误。
我需要一些帮助来理解在什么情况下会发生以下崩溃:
Hardware Model: iPhone3,1
Code Type: ARM (Native)
Parent Process: launchd [1]
OS Version: iPhone OS 5.0.1 (9A405)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000010
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x3427eb30 _class_isInitialized
1 libobjc.A.dylib 0x3427e8d6 _class_initialize
2 libobjc.A.dylib 0x3427e88e prepareForMethodLookup
3 libobjc.A.dylib 0x3427e76a lookUpMethod
4 libobjc.A.dylib 0x3427e008 objc_msgSend_uncached
5 CoreFoundation 0x33f7c020 CFRetain
6 CoreFoundation 0x33f85bac +[__NSArrayI __new::]
7 CoreFoundation 0x33f85ac6 -[__NSPlaceholderArray initWithObjects:count:]
8 CoreFoundation 0x33f85806 +[NSArray arrayWithObjects:count:]
9 CoreFoundation 0x33fa0e92 -[NSDictionary allKeys]
10 AClockworkBrain 0x0008f46e -[ItemManager getRandomItem] (ItemManager.m:360)
......
谢谢。
最佳答案
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x3427eb30 _class_isInitialized
1 libobjc.A.dylib 0x3427e8d6 _class_initialize
2 libobjc.A.dylib 0x3427e88e prepareForMethodLookup
3 libobjc.A.dylib 0x3427e76a lookUpMethod
4 libobjc.A.dylib 0x3427e008 objc_msgSend_uncached
5 CoreFoundation 0x33f7c020 CFRetain
6 CoreFoundation 0x33f85bac +[__NSArrayI __new::]
7 CoreFoundation 0x33f85ac6 -[__NSPlaceholderArray initWithObjects:count:]
这次崩溃是过度发布或损坏的标志。具体来说,您字典中的一个键已被过度释放和/或损坏。特别是,isa 指针现在指向垃圾。
当 allKeys 尝试创建所有键的临时数组时,它会尝试保留损坏的对象(通过 CFRetain,但将其视为对 保留)。运行时无法将 isa 指针识别为已初始化的类(因为它指向垃圾),它会尝试对该“类”调用 initialize,从而导致崩溃。
现在,损坏的 isa 可能是一个指向可读但垃圾菜单的值,这会导致运行时深层崩溃。最常见的是,这是因为对象被过度释放,然后某些结构恰好在同一位置被 malloc(),并且该结构恰好有一个指针作为第一个条目,这是结构的一种完全常见的模式。
修复?
首先,运行分析器并修复它提示的任何问题。
接下来,检查作为该字典中键的对象的所有使用。看看您是否可以找到可能发生过度释放的位置。
最后,尝试打开僵尸并查看是否可以重现崩溃。
关于objective-c - NSDictionary allKeys 崩溃 - 无法理解崩溃报告情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9589382/
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
这是在Ruby中设置默认值的常用方法:classQuietByDefaultdefinitialize(opts={})@verbose=opts[:verbose]endend这是一个容易落入的陷阱:classVerboseNoMatterWhatdefinitialize(opts={})@verbose=opts[:verbose]||trueendend正确的做法是:classVerboseByDefaultdefinitialize(opts={})@verbose=opts.include?(:verbose)?opts[:verbose]:trueendend编写Verb
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
当我在Rails控制台中按向上或向左箭头时,出现此错误:irb(main):001:0>/Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in`blockin_rl_dispatch_subseq':invalidbytesequenceinUTF-8(ArgumentError)我使用rvm来管理我的ruby安装。我正在使用=>ruby-2.0.0-p247[x86_64]我使用bundle来管理我的gem,并且我有rb-readline(0.4.2)(人们推荐的最少