Memory Leak question

Posted by franz on Stack Overflow See other posts from Stack Overflow or by franz
Published on 2010-05-24T05:54:34Z Indexed on 2010/05/24 6:01 UTC
Read the original article Hit count: 360

Filed under:
|
|

I am having a memory leak issue with the following code. As much as I can tell I don't see why the problem persists but it still does not release when called. I am detecting the problem in instruments and the following code is keeping its "cards" classes alive even when it should had released them. Any help welcome.

... 
...
-(id)initDeckWithCardsPicked: (NSMutableArray*)cardsPicked andColors:(NSMutableArray*)cardColors
    {
        self = [self init];
        if (self != nil) {
            int count = [cardsPicked count];
            for (int i=0; i<count; i++) {
                int cardNum = [[cardsPicked objectAtIndex:i] integerValue];
                Card * card = [[MemoryCard alloc] initWithSerialNumber:cardNum position: CGPointZero color:[cardColors objectAtIndex:i]];
                [_cards addObject: card];
                [card release];
            }
        }
        return self;    
        }

- (id) init
{
    self = [super init];
    if (self != nil) {
        self.bounds = (CGRect){{0,0},[Card cardSize]};
        self.cornerRadius = 8;
        self.backgroundColor = kAlmostInvisibleWhiteColor;
        self.borderColor = kHighlightColor;
            self.cards = [NSMutableArray array];
        }
          return self;
}
...
...

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c