Question

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.

Was it helpful?

Solution

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.

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