turbo
turbo

Reputation: 589

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?

Upvotes: 0

Views: 1831

Answers (2)

Keshav
Keshav

Reputation: 1133

The problem is that it is being dereferenced afterwards .Please use the keyword strong so that it is not being dereferenced.

Upvotes: 1

Bisca
Bisca

Reputation: 6763

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

Upvotes: 1

Related Questions