-1

I have a lot of objects named _Obj_1, _Obj_2, etc...
And I want to release all.

I'm using KVC. In particular to release all, i use:

MyClass *obj = nil;
for ( int i=1 ; i<=14; i++ ) {
  obj = [self valueForKeyPath:[NSString stringWithFormat:@"_Obj_%d", i]];
  [obj release];
}

clang analyzer tell me for [obj release];

Incorrect decrement of the reference count of an object that is not owned at this point by the caller?

How can I fix it?

It's not an ARC project.

Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184
elp
  • 8,021
  • 7
  • 61
  • 120
  • 2
    Why are you using this for releasing that poor object? This really is a hackish antipattern. –  Dec 14 '12 at 14:34
  • well, thanks. Now, with comments/response/negative vote i know that is a stupid way to release obj with kvc. Thanks. – elp Dec 14 '12 at 14:46

1 Answers1

2

This can be fixed very easily

If you don't own the object (you didn't call retain), don't release it!

Instead of having lots of variables with the same name, use an array to hold the objects. Then the releasing will be only the release of an array.

Sulthan
  • 128,090
  • 22
  • 218
  • 270