게임의 어려운 부분을 코딩 한 후에 메모리 관리 버그를 발견했습니다.코드가 누출되거나 작동하거나 누출되거나 충돌하지 않습니다. 이것은 자동 해제 문제가 아닌 것 같습니다.
개체는 사용자 지정 클래스가있는 NSMutableArray입니다.
- (void) spawnObjects
{
for (int index = 0; index < INITIAL_OBJECTS; index++)
{
[objects addObject:[[[MatchObject alloc] initWithImageNameID:(index % 3)] autorelease]];
[[objects objectAtIndex:index] setPosition:[GameLayer randomPoint]];
}
...
}
나중에이 기능을 사용합니다.
- (void) checkAllSprites
{
NSMutableArray *spritesToDelete = [NSMutableArray array];
for (int index = 0; index < [points count] - 1; index ++)
{
for (MatchObject *planetLike in objects)
{
CGPoint point1 = [[points objectAtIndex:index] CGPointValue];
CGPoint point2 = [[points objectAtIndex:index+1] CGPointValue];
if ([GameLayer lineIntersectsCircle:point1 :point2 :[planetLike position] :16.0f])
{
ParticleSystem *planetDeath = [ParticlePlanetDeath node];
planetDeath.texture = [[TextureMgr sharedTextureMgr] addImage:@"fire.pvr"];
planetDeath.position = [planetLike position];
[self addChild:planetDeath z:0 tag:2];
[spritesToDelete addObject:planetLike];
[self removeChild:planetLike cleanup:YES];
}
}
}
[objects removeObjectsInArray:spritesToDelete];
[spritesToDelete removeAllObjects];
}
첫 번째 기능에서 자동 응답을 사용하지 않으면 앱이 정상적으로 작동합니다. 그렇게하면 할당 해제 된 개체 ([MatchObject 위치])에 액세스하려고합니다.
무엇이 잘못 되었나요?!
addChild 및 removeChild에 대한 코드를 표시 할 수 있습니까? –