In my game, I allocate some UIImageViews programmatically with the following code:
blocks[1] = [[UIImageView alloc] initWithFrame: CGRectMake(200, y1, kBlockHeight, kBlockHeight)];
blocks[2] = [[UIImageView alloc] initWithFrame: CGRectMake(320, y2, kBlockHeight, kBlockHeight)];
blocks[3] = [[UIImageView alloc] initWithFrame: CGRectMake(440, y3, kBlockHeight, kBlockHeight)];
blocks[4] = [[UIImageView alloc] initWithFrame: CGRectMake(560, y4, kBlockHeight, kBlockHeight)];
blocks[1].backgroundColor = [UIColor blackColor];
blocks[2].backgroundColor = [UIColor blackColor];
blocks[3].backgroundColor = [UIColor blackColor];
blocks[4].backgroundColor = [UIColor blackColor];
[self.view addSubview: blocks[1]];
[self.view addSubview: blocks[2]];
[self.view addSubview: blocks[3]];
[self.view addSubview: blocks[4]];
and it works fine, but when I try to get rid of the objects and restart,
for (int i = 1; i<= 4; i++) {
blocks[i] = nil;
//ARC won't let me call [blocks[i] release];
NSLog(@"releasing blocks");
}
they still stay on the screen. They don’t interact with anything, but still stay drawn on the screen. Why is this, and what should I do to get rid of the objects?
Your UIImageViews are still being retained by your viewController’s view. Try using: