简体   繁体   中英

crash on NSString stringWithFormat

I have a line code that creates a NSString like below,

NSString *paramString = [NSString stringWithFormat:@"?user_id=%@&x=%@&y=%@",_selectedID, _selectedX,[MyModel shared].currentUser.userID];

I do get crash report as below :

crash in :
Thread 0 crashed:
libobjc.dylib      objc_msgSend + 16
CoreFoundation _NSDescriptionWithLocaleFunc + 68
CoreFoundation _CFStringAppendFormatCore + 6004
CoreFoundation _CFStringCreateWithFormatAndArgumentsAux + 116
Foundation [NSPlaceholderString initWithFormat:locale:arguments] + 160

userID in currentUser is a NSString. _selectdID and _selectedX are both NSStrings passed from VC1 --> VC2 ---> VC3. In VC2 and VC3, both are declared as @property(nonatomic,assign) .

However this crash only occurs for around 1% of users and all of them are on iOS 7.1.1 as per crash report.

I tried to simulate it with no luck. Is it because of memory is released ? Is there any to simulate this?

Try to declare your NSString properties with copy or strong modifiers in order to ensure they are in memory. They can be deallocated and their pointers make reference to another var

问题在于它之后被取消引用了。请使用关键字strong这样它才不会被取消引用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM