App not functioning the same on 32 bit devices - NSInteger vs intValue

喜欢而已 提交于 2019-12-11 10:54:57

问题


I noticed after increasing the number of arrays that are instantiated into memory from 8 to 23, my app just stops running

[NSMutableArray addObject:obj]

on the 13th array on 32 bit devices only. On an iPad Air 2 (device and sim) and iPhone 6 (device and sim) all 23 arrays are populated and the app functions as expected.

I understand there's a point at which a device will run out of available memory, and I noticed in Xcode on a 32 bit device, the app memory was hovering around 50-55mb, but the app doesn't crash or give a memory warning in the console. On a 64 bit device or sim, at the same point of interest, the app memory is around 90-95mb?

1) how is memory for 32 bit devices different from 64 bit devices when it comes to the amount of data that can be instantiated?

2) is there a certain number of arrays that can be init to memory unrelated to the size, considering I could populate 2 out of 23 arrays with a single small object and the first would have the right count and the 2nd (any array with an ID > 13) would be 0 like this?

    if (obj.eventTypeID == [NSNumber numberWithInt:1]) {obj.color = [UIColor whiteColor];[array1 addObject:obj];}
//ALL ARRAYS ALWAYS POPULATE NO MATTER THE COUNT OR SIZE BETWEEN 1 AND 13
    if (obj.eventTypeID == [NSNumber numberWithInt:13]) {obj.color = [UIColor greenColor];[array13 addObject:obj];}
//ALL ARRAYS ARE ALWAYS EMPTY BETWEEN 14 AND 23
    if (obj.eventTypeID == [NSNumber numberWithInt:23]) {obj.color = [UIColor redColor];[array23 addObject:obj];}

Hopefully that's enough to go on. Just remember, the app works as expected on 64 bit, but not in 32 bit.


回答1:


For what it's worth, I ended up fixing the problem by casting the conditional statements using intValue...genius, I know...

if ([obj.eventTypeID intValue] == 1)

Although this solved a huge bug, I still don't understand why the precision of doing it the other way is any different.

obj.eventTypeID is an NSInteger

So why is this any different? More importantly, why is this difference powerful enough to stop the thread from processing these conditions inside a loop if it's not an intValue? These are some of the unanswered parts of this question, but it's long been solved with the solution above.



来源:https://stackoverflow.com/questions/31193731/app-not-functioning-the-same-on-32-bit-devices-nsinteger-vs-intvalue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!