I had developed an app and now I'm using Instruments to see the memory usage. I have a problem understanding the retain/release process of my object. This is what Instruments says:
The retain count increase when I add my object into an array, when I add it on my view and when I take off from the array.
So, when I use removeFromSuperview
the object retainCount
will never be zero, so the object don't release the memory.
EDIT 1: I forgot to say i'm using ARC.
EDIT 2:
I describe exactly what happen :
I create the object together other objects in a class called NKLevelGenerator
. Into it i alloc the NKIngredient
s and then i add all to a NSArray
which will be returned. Here the retain count of every object is 2. In my NKLevelVC
, my ViewController
, i use this instruction :
[level addObjectsFromArray:[levelGenerator level1WithDelegate:self ciotola:ciotola bagliore:bagliore difficulty:NKDifficultyHard]];
Object level
is a NSMutableArray
that i alloc
and init
in viewDidLoad
.
From here i call another method which performs this operations :
- (void)insertInArrayRandomly {
for (int i=0; i<[level count]; i++) {
[ingredienti insertObject:[level objectAtIndex:[[indexes objectAtIndex:i]integerValue]] atIndex:i];
}
}
Object ingredienti
is another NSMutableArray
that I alloc
and init
in viewDidLoad
. indexes
is an array of NSInteger
which contains random indexes to extract NKIngredient
object randomly.
Then i'm doing this :
NKIngredient *ing = [ingredienti objectAtIndex:index];
[[self view] insertSubview:ing belowSubview:navBar];
[ing animateIngredient];
[ingredienti removeObject:ing];