In a lot of code samples, also on the Apple documentation website, you will see this kind of pattern. The UIAlertView is called with "show" and "release" in sequence.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Panic!"
message:@"The world is gonna explode!"
delegate:nil cancelButtonTitle:@"Who cares?"
otherButtonTitles:@"Boom!", nil];
[alert show];
[alert release];
NSLog(@"released!");
When you run this code, the "released!" log line will be shown while the UIAlertView box is still on screen. It seems like an odd pattern to me to release this object when it's still seen on screen. What is the idea behind this, isn't this against what is common with memory management? If this "show" call would be blocking, I could see how this pattern would be safely freeing the memory. But since the NSLog method is executed, it continues executing your code.
release doesn’t mean that the object will be disposed off right away. It just means that your code doesn’t want to access it any more after that point. Other code (like the system frameworks) might and so they retained it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With