Pawan
Pawan

Reputation: 87

NSString Memory Warning in objective c

    NSString * str1 = nil;
    NSString * str2 = nil;
    str1 = @"";
    str2 = @"";

I got memory warning "Value stored to 'str1' is never read" on above statement. Is there any other way to do the same?

Upvotes: 1

Views: 552

Answers (1)

paxdiablo
paxdiablo

Reputation: 881423

The warning:

Value stored to 'str1' is never read

is simply telling you that you have a variable which you set and never use. You'll see the same sort of thing with:

static void xyzzy (void) {
    int plugh = 7;
}

where clearly the plugh variable is not being used.

That's not a serious problem (otherwise it would be an error rather than a warning) but it does notify you that either:

  • you're wasting space (and possibly time if you're setting it); or
  • it may be indicative of another problem.

One example of the latter is if you are accidentally using str2 somewhere where you intended to use str1 (possibly due to a cut-and-paste where you forgot to change the pasted code).

As to how to fix it:

  • If you're really not using it (and have no intention of using it), just get rid of it.
  • If you are going to use it, commenting it out temporarily will get rid of the warning until you do.
  • If you think you should be using it, then you have a problem elsewhere and you should track that down.

Upvotes: 7

Related Questions