Hi,
Im not sure it's me (Properly is..) but I just don't understand the memory leaks I get in my program after upgrading to 4.1
In my .h file I have:
NSMutableArray pieces;
In the Init method I do following:
pieces = [[NSMutableArray alloc] init];
Then I load some pieces to the array..
-(void) loadImages() {
for (int i = 0; i < piecesCount; i++) {
//Piece extends UIImageView, just added some new properties to this object
Piece *pieceImageView = [[Piece alloc] initWithImage:Image];
...
...
[pieces pieceImageView];
// Add puzzel piece to the view
[self.view insertSubview

ieceImageView atIndex:subViewIndex];
subViewIndex++;
// Clean up
[pieceImageView release];
}
When the user have looked though the pieces and want to go to next view I (Same view new images)
I would like to clean up, then I call same method again (loadImages)
BUT, when I try to clean-up it looks like I get some leaks, and do not understand why.. I have many many different ways non of them works:
- (void) cleanUp() {
1)
NSMutableArray *delete = [NSMutableArray array];
for(Piece *p in pieces) {
[delete addObject

];
[p removeFromSuperView];
}
for (Peice *dt in delete)
[pieces removeObject:dt];
2)
for (UIView *view in self.view.subviews) {
if ([view isKindOfClass:[Tile class]])
[view removeFromSuperview];
[pieces removeAllObjects];
3)
for(Piece *p in pieces)
[p removeFromSuperView];
// This crach, when removing from superview I can see I loose ref to it.. So why do I get the leak
[pieces release];
}
I hope one of you can tell me what Im doing wrong, I know it's me, just can't figure it out..
Thank you!