gpambrozio / BlockAlertsAnd-ActionSheets

Beautifully done UIAlertView and UIActionSheet replacements inspired by TweetBot
http://codecropper.com/2012/01/replicating-tweetbots-alerts-and-action-sheets/
MIT License
1.41k stars 268 forks source link

Memory Leak #52

Closed bmueller closed 11 years ago

bmueller commented 11 years ago

I'm seeing a memory leak in Instruments whenever I open a BlockAlertView. (My project's running ARC, but I'm using a non-ARC version of BlockAlertView.) Has anyone experienced this? And any ideas on how to fix?

barrettj commented 11 years ago

I have an ARC project running the current BlockAlertView (non-ARC) and get no leaks in Instruments.

What type of object does it say it's leaking for you? Can attach screenshots/the instruments run?

bmueller commented 11 years ago

It's leaking a UIResizableImage - looks like it's the "background" UIImage object in the BlockAlertView class. I'm calling the following line in both the "initialize" method and the "initWithTitle" method:

    background = [[background stretchableImageWithLeftCapWidth:0 topCapHeight:kAlertViewBackgroundCapHeight] retain];

I need to call it in both methods to ensure that the theming I apply to the background image is correct. I suspect that calling retain twice is what is causing the issue, but I'm not familiar enough with retain counts, etc to know how to solve this issue. Any ideas?

barrettj commented 11 years ago

Ahh, if it's in something you customized then I can't really give an answer as I don't have your code. Why are you calling that method yourself instead of just replacing alert-window.png with your custom png?

bmueller commented 11 years ago

Yeah, I figured, and the leak's not really that big of a deal, just annoying :)

And I have to call it a second time because when a new theme gets applied and the background image has to be replaced, for some reason the caps on the stretchable image get all messed up if it only gets called during the initialize method.

barrettj commented 11 years ago

Well, when you're calling it in the init method, add this before to avoid the leak:

if (background) {
    [background release];
    background = nil;
}
bmueller commented 11 years ago

Works like a charm, thanks for the help!