I’ve been playing around so much now with ObjC that I feel lost as far as “autoreleasing” is concerned.
in my .h:
NSString *sAStringMember;
in my .m:
-(void) createAString
{
NSString *sAString = [NSString stringWithString:[dummyCode...get String ffrom some input field for instance]];
sAStringMember = sAString;
}
Several short questions:
-
In “createAString:” an autoreleased string “sAString” is created. If sAString is autoreleased (when is this going to happen?), also my member “sAStringMember” will point to an invalid address, correct?
-
If above assumption is correct, would it be an option to release sAStringMember before assigning sAString to it and then retain it?
-
Best would be use “copy” to copy sAString to sAStringMember I suppose?
René
(1) Yes.
(3) Either
-retainor-copyis fine.The best would be using declared property.
(Also, please avoid Hungarian notation.)