Hi guys,
i got a problem,
if I run this code:
NSString *xml = [[NSString alloc] init];
xml=[NSString stringWithFormat:@"<%@>", @"msg"];
NSLog(@"%@\n",xml);
[xml release];
I got:
2010-09-07 11:45:15.523 test[1312:207] <msg>
2010-09-07 11:45:15.527 test[1312:207] *** -[CFString release]: message sent to deallocated instance 0x3d52ba0
I have red the memory guide and I think that:
if i create an object using the alloc
& init
methods, I should release that object, but the rule does not play well here, why?
thanks
UPDATED
it seems that this line xml=[NSString stringWithFormat:@"<%@>", @"msg"];
is the problem.
I replaced it by xml=@"something";
and it worked.
any idea why I can not use the stringWithFormat
method here?
thanks again
UPDATED
Thanks for the answers @(Douwe Maan, BoltClock, Rod)
I have updated the code, just testing another way:
NSString *xml = [[NSString alloc] initWithFormat,@"<%@>", @"msg"];
NSLog(@"%@\n",xml);
[xml release];
interesting: if i run that code with the debug option enabled i get a message saying:
*** -[CFString _cfTypeID]: message sent to deallocated instance 0x3954ab0
but if i run it without the debugging tool, it never sends a message saying that.
questions:
1. is it normal that the error message will not appear if i am not running the project with the debug tool?
2. so, what is the problem with initWithFormat
?, is it the same that has stringWithFormat
? (i think it does not create an autoreleased instance)
3. how may i know that some method returns an autoreleased instance?, is there some naming convention anywhere?
thanks!