我遇到以下代码的内存泄漏问题。据我所知,我不明白为什么问题仍然存在,但在调用时它仍然没有释放。我正在检测仪器中的问题,并且以下代码使其“卡”类保持事件状态,即使它应该释放它们。 欢迎任何帮助。
...
...
-(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;
}
...
...
最佳答案
如果不查看其余代码,很难知道问题出在哪里,但是您尝试过在 xcode 中使用静态分析器吗?它对于查找内存泄漏非常有值(value)。
要使用它,请从“构建”菜单中选择“构建和分析”。更多详情请参见Apple's dev website.
关于iphone - 内存泄漏问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2895030/