Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Fix memory management for static block variables in UIAlertView+MKBlockAdditions #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

albertodebortoli
Copy link

If objects referenced in the blocks are deallocated, in the next invocation of alertViewWithTitle:message:cancelButtonTitle:otherButtonTitles:onDismiss:onCancel: block arguments still reference to deallocated instances causing crash.
Fix the case if more than one UIAlertView is shown using block-based category method.
Add thread safety.

@@ -70,6 +70,11 @@ + (void)alertView:(UIAlertView*) alertView didDismissWithButtonIndex:(NSInteger)
{
_dismissBlock(buttonIndex - 1); // cancel button is button 0
}

[_cancelBlock release];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting errors on these lines:

UIAlertView+MKBlockAdditions.m:108:6: Use of undeclared identifier '_cancelBlock'
UIAlertView+MKBlockAdditions.m:109:5: Unknown type name '_cancelBlock'; did you mean 'CancelBlock'?

@drewish
Copy link

drewish commented Aug 13, 2012

I think that should probably be:

[alertView.cancelBlock release];
alertView.cancelBlock = nil;
[alertView.dismissBlock release];
alertView.dismissBlock = nil;

@drewish
Copy link

drewish commented Aug 13, 2012

Yeah so it looks like pull request #7 made those into dynamic properties. I'm not sure if your change is still necessary but it should probably become something more like what I showed above.

@drewish
Copy link

drewish commented Aug 13, 2012

Okay I rebased your commit and fixed that: drewish@1994aa5

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants