Ive have used the static analyser to look through my code and have arrived at the following question.
NSString *string = [[NSString alloc] init];
string = [object name];
This give me a memory error saying that the initial value is never read.
I replaced it with the following
NSString *string = [[object name]retain];
Is this better/correct coding?
Cheers
I have seen someone else do this exact thing.
NSString *string = [[NSString alloc] init];creates a new object and assigns it to string.string = [object name];Assigns the name ofobjectto string. It is similar to sayingint a = 0; a = 4,0has no effect on the4. The problem with your code is that[[NSString alloc] init]creates a new object with a retain count of 1, because you do not release it it leaks.[object name]returns an autoreleased object which will disappear at the end of the runloop.In short, use
NSString *string = [[object name] retain];