Hi all,
I have an issue with releasing a view too many times. Although simple in theory because im moving uiview to uiview, which is a subclass of uiview and being animated and so on its not something that I can easily fix. It only crashes 10% and only under certain conditions and only 30% of the time even under these conditions.
So in other words its kinda complex. Sometimes in my dealloc method the retain count of this UIView is already 1 (which gets released when the view is released) and so shouldn't be released again. So what I did is this:
if ([mainView retainCount] > 1) {
NSLog(@"released");
[mainView release];
}
Consistant with the crashes released is usually called, but not always and it happens pretty much when I would sometimes expect it to crash. I've checked for leaks with this code and it never leaks.
Now the actual question... Is it wrong to release something due to its retain count? I've tried many different ways to fix this and so far this is the only reliable and non leaking one.
EDIT: If no then what is the better way to copy one UIView to another UIView?
mainView = newView;
[newView release];
I've tried releasing the mainView first then calling copy on the newView but this crashes. The above also works perfectly except the retain count is sometimes 1 lower than expected even though its never released ANYWHERE else in the code.