NSString
s are also objects. They go by the same memory management rules. If you sin against those rules you will get a pointer to invalid memory and it will look like "invalid" data.
For example:
myString = [NSString stringWithString:@"foo"];
This will create an NSString*
that's got autorelease on. When you're assigning it to an ivar that autorelease pool will soon pop putting the retain count back to 0 and dealloc
'ing it while you still have a reference to it!
Naughty.
Instead, either retain it or use:
myString = [[NSString alloc] initWithString:@""];
This returns an owning reference. Remember to [myString release];
in dealloc
.
This is just one example/case of bad memory management. Read the docs on how to properly manage your object lifecycle. Really.