Question

i think i don't finish to understand all about memory and that stuff but this is my problem:

I have a variable defined idActual on a view that will be pushed (var defined in its header), i can read (NSLog(idActual)) and set it to nil without problems. BUT when i change its value i get an CFString error, that its supposed to be due to bad memory management, i've tried this:

i can do this: nextView.idActual = nil;

i cant do this:

a) nextView.idActual = @"1";

b) NSString *str = [NSString stringWithFormat:@"1"]; 
   nextView.idActual =  str;

c) NSString *str = [[NSString alloc] initWithFormat:@"1"];
   nextView.idActual = str;
   [str release];

a, b and c always give me the CFString error: *** -[CFString isEqualToString:]: message sent to deallocated instance

Was it helpful?

Solution

It appears that the CFString (NSString) that is contained in nextView.idActual has already been released when you go to change the value. If you can post more of the related code, that would help.

I'm guessing that idActual is declared as @property(nonatomic,retain). When you try to set a new value into idActual, the setter method for that property is called (It's possible that the setter was automatically generated). The first thing that the setter method is doing is trying to compare the old value and the new value - and then it crashes.

When that setter method attempts to compare the new value to the old value, it runs into trouble because the old value is already deallocated.

Are you calling [nextView.idActual release] before you assign these new values ? If you are, comment out that line, and see if that fixes your problem. The auto-generated setter method will release the old value for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top