开发者

Memory Leak in very small method (objective-c/iphone)

I have a Problem with some very small method inside my iPhone application.

The sample code (similar to the real code):

+ (void) drawSomething: (UIView *) theView anImpo开发者_如何学CrtantNumber: (NSNumber *) importantNumber {
    UIImage *tehImage = [[WebviewUtil sharedInstance] goldStarImage];

    int iCount = 0;
    double roundedNumber = round([importantNumber doubleValue]);
    for (; iCount <= (4 - roundedNumber); iCount++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((iCount * 15) + 9, 6, 14, 13)];
        [imageView setImage:tehImage];
        [imageView setOpaque:YES];
        [theView addSubview:imageView];
        [imageView release];
    }
}

In the Line UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake the Instruments reports an memory leak. Can anyone give me a hint, what the mistake is? I thought, the [imageView release]; would do it ?!

Many thanks, if anyone can help me :))


If you are using Instruments to detect leaks, take into account the fact the leaks will show you the point where the leaked memory is allocated, not the point where the leak actually happens.

Your code seems right to me. You correctly release imageView after adding it as a subview. The problem might lay with theView or any other object containing it. So you can review that part in your code (e.g., is theView correctly released?)


have u used imageNamed: method? because this method causes memory leak in imageView :)


try to keep break point at for (; iCount <= (4 - roundedNumber); iCount++) and see to it that at any point 4-roundedNumber does not go out of range or having some unusual value that it should not have...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜