gpt4 book ai didi

iphone - 遇到分配/释放问题

转载 作者:行者123 更新时间:2023-12-03 21:06:47 24 4
gpt4 key购买 nike

我已经尝试了许多不同的尝试,但总是以泄漏或错误告终。这是我的代码,删除了分配和释放位。我想知道人们建议我如何去做这件事?

.h

#import "MatchingColors.h"

@interface MagicSchemeView : UIViewController {

NSMutableArray *colors;

}

.m

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

然后在MatchingColors.m中:

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

return result;

}

就像我说的,我在这里分配和释放的尝试似乎出了问题。有想法吗?

最佳答案

这应该有效

[颜色发布]的地方;会在你完成之后。一旦您知道不需要它,就会立即执行,或者在释放时完成。确保 dealloc 是发布此版本的最后手段。

.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;}

关于iphone - 遇到分配/释放问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6361347/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com