开发者

Having trouble with this alloc/releasing issue

开发者 https://www.devze.com 2023-03-13 01:07 出处:网络
I\'ve tried numerous different attempts at it but always ends in leaks or errors. So here is my code开发者_运维知识库, with the allocating and releasing bits taken out. I\'d like to know how people su

I've tried numerous different attempts at it but always ends in leaks or errors. So here is my code开发者_运维知识库, with the allocating and releasing bits taken out. I'd like to know how people suggest i should go about doing this?

.h

#import "MatchingColors.h"

@interface MagicSchemeView : UIViewController {

    NSMutableArray *colors;

}

.m

colors = [MatchingColors monochromaticWithH:h S:s B:b WithComplementary:NO];

Then in MatchingColors.m:

+(NSMutableArray *)monochromaticWithH:(float)h S:(float)s B:(float)b WithComplementary:(BOOL)complementary {

    return result;

}

Like i say, my attempts at allocating and releasing here seem to be going wrong. Ideas?


This should work

A place for the [colors release]; would be after you're done with it. Which would be as soon as you know you don't need it, or would be done on dealloc. Make sure dealloc is a last resort to put this release.

.m:

colors = [[MatchingColors monochromaticWithH:h S:s B:b WithComplementary:NO] retain];


+(NSMutableArray *)monochromaticWithH:(float)h S:(float)s B:(float)b WithComplementary:(BOOL)complementary 
{      
    NSMutableArray *result = [[[NSMutableArray alloc] init] autorelease];

    // Create the result here

    return result;
}
0

精彩评论

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