I have a game I am working on. As the user buys things UIImageViews are added to the view. Then the view is added to an NSMutableArray to store what objects have been added to the view. All of the UIImageViews are ivars.
At the end of the round all the views get removed from the screen but the objects still exist, even though I set them to nil.
Later in the program I do a simple test to check if the program is gone or is still hanging around.
From my understanding I am creating a UIImageView pointer object called 'userObjects'. I am using this this to iterate through an array to remove the object from the view and also setting it to nil.
At the end of the for loop I clean the array with removeAllObejcts. Now my gut is telling me something is wrong by the time I get to the array to clear it. I have already removed the objects from the view, and set them to nil. So the array would be holding pointer objects that pointers that should have been freed? I would think I would get some kind of an error, but I don't, and I don;t because the objects have not been set to nil.
At the end of the round all the views get removed from the screen but the objects still exist, even though I set them to nil.
Code:
for (UIImageView __strong *userObject in objectsArray) {
user2Gold += (userObject.tag == 200)? 3 : 0;
[[self.view viewWithTag:userObject.tag]removeFromSuperview];
userObject = nil;
}
[objectsArray removeAllObjects];
Later in the program I do a simple test to check if the program is gone or is still hanging around.
Code:
if (spyView) {
NSLog(@"SpyView is their");
}
else{
NSLog(@"spyView is gone");
}
From my understanding I am creating a UIImageView pointer object called 'userObjects'. I am using this this to iterate through an array to remove the object from the view and also setting it to nil.
At the end of the for loop I clean the array with removeAllObejcts. Now my gut is telling me something is wrong by the time I get to the array to clear it. I have already removed the objects from the view, and set them to nil. So the array would be holding pointer objects that pointers that should have been freed? I would think I would get some kind of an error, but I don't, and I don;t because the objects have not been set to nil.