I have some code that results in a EXC_BAD_ACCESS error:
recordIDAsString = [
NSString stringWithFormat:@"%i", (int)abRecord.recordID
];
propertyIDAsString = [
NSString stringWithFormat:@"%i", (int)abProperty.propertyID
];
identifierAsString = [
NSString stringWithFormat:@"%i", (int)abProperty.identifier
];
recordIDAsString, propertyIDAsString, and identifierAsString are all defined in the interface. The code is contained in an editing view controller, and the three *AsString variables seem to work fine until the save button is pressed, when their values become invalid. However, I've discovered that the following code does work:
NSString *tempRecordIDAsString = [
NSString stringWithFormat:@"%i", (int)abRecord.recordID
];
NSString *tempPropertyIDAsString = [
NSString stringWithFormat:@"%i", (int)abProperty.propertyID
];
NSString *tempIdentifierAsString = [
NSString stringWithFormat:@"%i", (int)abProperty.identifier
];
recordIDAsString = [tempRecordIDAsString copy];
propertyIDAsString = [tempPropertyIDAsString copy];
identifierAsString = [tempIdentifierAsString copy];
I thought I only had to manage memory when I call alloc or init, so my question is: what is happening in the first code example that causes the memory to become invalid?