遇到一个问题,跟踪了半天才发现原因。(现象是,客户老是说在下载的过程中,过一会就出现崩溃的现象, 只要点了下载按钮, 不做任何操作, 然后期刊就开始正常下载了,过大概5分钟后,再去看,程序就已经崩溃了)
在做《时装传媒》ipad应用时,首页的下载页面,下载时,会不断地去更新页面上的下载进度,同时还有一个15秒的timer, 会每15秒切换当前显示的是男装,女装或者艺术刊页面。这个timer会把当前的scrollView中显示的封面图片进行移除,然后再替换,以实现自动更换首页封面的功能
崩溃时提示:
Collection <UIButtonContent: 0x2341234> was mutated while being enumerated
(在网上搜了一下,发现有一个类似的问题:'NSGenericException', reason: '*** Collection <__NSArrayM: 0x8ef350> was mutated while being enumerated.')
根据这个提示, 想了一下,觉得应该在做遍历的过程中,修改了这个NSArray或者是NSMutableArray。后来想想, 这可能是多线程并发访问时出现的问题, 沿崩溃时的堆栈找了一下,果然找到。
因为我们在下载时, 使用了Block每当接受到数据,就去更新一下一个UIScrollView中的下载进度条的百分比。
而另有一个NSTimer, 会隔一段时间把这个UIScrollView中的全部元素清空,然后再重新添加, 因为可能有动态的元素需要添加或者删除。
运行时, 就会出现,两个线程同时去访问的情况, 当Block正在去更新UIScrollView中的这个元素时, NSTimer中可能正在执行清除操作,所以就崩了。
原来,在同一时间,不同的线程同时读取和修改了NSMutaleArray。
解决办法:避免多线程同时去修改一个对象, 避免做遍历时,这个对象被修改,根据这个思想,可以考虑加锁,或者直接使用atomic的方式来做。
分享到:
相关推荐
Java has a well-established past, being more than 20 years old, but at the same time, it is new, functional, reactive, and sexy. This is a language that developers love, and at the same time, it is ...
准入突变代理(txn2 / amp)实施示例项目。 示例Webhook实现。 安装 ...# pod to be mutated kubectl apply -f ./k8s/200-pod-mutate-test.yml 发展 释放 goreleaser --skip-publish --rm-dist --skip
字节查找器 给定一个文件和一个使 MobileSafari 崩溃的文件的变异版本,这将找到导致变异版本使 MobileSafari 崩溃的字节。... 用法: finder.sh -f ./original.mov -m ./mutated.mov [-t 11] [-q]
|IDH1|Feature|Categorical |- |isocitrate dehydrogenase (NADP(+))1 (0 = NOT_MUTATED; 1= MUTATED)|N/A|no| |TP53|Feature|Categorical | - |tumor protein p53 (0 = NOT_MUTATED; 1 = MUTATED)|N/A|no| |ATRX|...
Each mutated version is called a mutant and tests detect and reject mutants by causing the behavior of the original version to differ from the mutant. This is called killing the mutant ( ) 用来衡量...
Improving Testing Coverage for Safety Critical System by Mutated Specification
//工作中遇到的: ... Prop being mutated: “flag” 原因:子组件直接更改父组件中的属性 解决办法:无法直接更改可以用$emit()传递参数至父组件中,然后在绑定在子组件中的父组件方法里更改父组件属性 例: //
Edlib· 一个轻量级且超快速的C / C ++库,用于使用进行序列比对。 计算两个字符串的编辑距离很简单: edlibAlign ( " hello " , 5 , " world! " , 6 , edlibDefaultAlignConfig()).editDistance;...
This book is for people who know the pain of working on ...four people wrote and that mutated into a huge, sprawling, incoherent mess. We’ ve looked the beast in the eye and barely survived......
vue不推荐直接在子组件中修改父组件传来的props的值,会报错 [Vue warn]: Avoid mutating a prop directly since the value ... Prop being mutated: “result” (found in component ) <input v-model="currentSe
mutated in this disorder is termed HFE.(1) HFE is homologous to major histocompatibility complex (MHC) class I proteins, but unlike MHC class I mole- cules, HFE does not present peptides to T cells.(2...
mutated in this disorder is termed HFE.(1) HFE is homologous to major histocompatibility complex (MHC) class I proteins, but unlike MHC class I mole- cules, HFE does not present peptides to T cells.(2...
布谷鸟优化算法 (COA) 的灵感来自一种名为布谷鸟的鸟类家族的生活。 这些鸟类的特殊生活方式及其在产卵和繁殖方面的特征是开发这种新的进化优化算法的基本动机。 与其他进化方法类似,布谷鸟优化算法 (COA) 从初始...
默认情况下,输入array是mutated 。 要返回新array ,请将copy选项设置为true 。 var arr = [ 1 , 2 , 3 , 4 ] ; var out = reverse ( arr , { 'copy' : true } ) ; // returns [ 4, 3, 2, 1 ]; console . log