Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 内存泄漏问题_Iphone_Objective C_Memory Leaks - Fatal编程技术网

Iphone 内存泄漏问题

Iphone 内存泄漏问题,iphone,objective-c,memory-leaks,Iphone,Objective C,Memory Leaks,以下代码存在内存泄漏问题。据我所知,我不明白为什么问题仍然存在,但调用时仍然无法释放。我正在检测仪器中的问题,下面的代码使它的“cards”类保持活动状态,即使它本应该发布它们。 欢迎任何帮助 ... ... -(id)initDeckWithCardsPicked: (NSMutableArray*)cardsPicked andColors:(NSMutableArray*)cardColors { self = [self init]; if (s

以下代码存在内存泄漏问题。据我所知,我不明白为什么问题仍然存在,但调用时仍然无法释放。我正在检测仪器中的问题,下面的代码使它的“cards”类保持活动状态,即使它本应该发布它们。 欢迎任何帮助

... 
...
-(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;
}
...
...
。。。
...
-(id)initDeckWithCardsPicked:(NSMutableArray*)cardsPicked和Color:(NSMutableArray*)CardColor
{
self=[self init];
if(self!=nil){
int count=[cardsPicked count];

对于(int i=0;i当您使用
addObject
将一张卡添加到_cardsnsmutableArray时,它会被发送一条保留消息。因此,只要您将_卡保留在内存中,它的每个组成部分都会保留一个指针。只要您的
dealoc
释放该数组,或者您在其他地方这样做,您就应该对所拥有的内容感到满意ted(假设您的initWithSerialNumber方法返回一个保留对象)。

如果不查看代码的其余部分,很难知道问题出在哪里,但是您是否尝试过在xcode中使用静态分析器?它对于查找内存泄漏非常有价值


要使用它,请从“构建”菜单中选择“构建和分析”。有关详细信息,请参见

我确实通过dealloc发布了阵列…[\u cards release];[super dealloc];…但据我所知,该类是从其他地方引用的,不允许发布?