Is it possible that NSZombie doesn't point out EXC_BAD_ACCESS with ARC? - ios

i'm currently working on an ios project with some people, one of us decided to use ARC in a part of the app.
Unfotunatly, we are currently experiencing some crashes when coming back from background.
Here are the steps we follow to crash the application, we perform them with the ios-simulator:
start the application
get on a ViewController A (coded with ARC)
get on a ViewController B (not coded with ARC -to be honest i don't
know if it's relevant-)
put the application in background.
simulate a memory warning (thx to the simulator)
start again the application, we'll be on the ViewController B
go back on the Viewcontroller A
the application crashes pointing the main function with an
EXC_BAD_ACCESS
We did try to use NSZombieEnabled to YES, but when we do it, the application doesn't crash and keeps running perfectly, so we wonder if it might be possible that NSZombieEnabled doesn't work well with ARC?
if anyone could give me a quick and clear insight about ARC and NSZombieEnabled that would be apreciated, i think i know how all of it works, but apparently i must be missing something.
Thanks anyway for your help and time.

Better than using the NSZombieEnabled, you should Profile the project, and use the Zombie instrument. When you do the same thing it should stop and say "zombie messaged", where you can click an arrow to see the class that is a zombie, and where it was allocated/deallocated.
I don't think the crash has to do with ARC, instead in viewDidUnload you are deallocating something, and then not setting a reference to nil - when you come back it tries to use the invalid reference.
Probably you would be better off if everything used ARC as it really helps to cure issues like this (the bug is very likely in the non-ARC code).

Related

iOS 10 UIKit Zombie Crash, Worked Fine in iOS 7-9

We've got an app that's fairly large now, and we recently upgraded to iOS 10. In doing so, a new bug was introduced, and we're at a loss for how to solve it.
The crash itself occurs during a call to layoutIfNeeded(). However, the crash does not occur unless the layoutIfNeeded() call is contained inside a UIView.animateWithDuration() block. No amount of weak referencing, delays, or dispatch calls seems to have any effect. The same crash can be triggered during a call to [super viewWillTransitionToSizeWithTransitionCoordinator].
"An Objective-C message was sent to a deallocated 'Bubble' object (zombie) at address: 0x10924f030."
Enabling Zombies shows that we have a Release call going to one of our UIView subclasses, which we've named Bubble. Nothing too special there, some layout constraints and a gesture recognizer.
The Instruments app hasn't helped much, nor has the new visual memory debugger in Xcode 8 (though it is awesome, surprisingly little documentation on the feature).
I've included a screenshot of Zombies during the crash here. While I know the retain count can be misleading, there are certainly some confusing points to the trace, and we could really use some help diagnosing this.
Again, this code worked fine before iOS 10. We've been unable to find any notes from Apple about underlying changes to UIKit that may have had an effect.
Some more brief info: [Bubble cleanBubbles] simply iterates over the subviews of any view passed in, and removes the subview if its a Bubble class.
Apologies on certain violations of naming conventions, I'm sure there's plenty to criticize!
Thanks

Weird crash while navigating back

My app crashes randomly when navigating back in a NavigationController. Here is what I know:
It happens randomly (sometimes, I can come back once or twice and if I reload the viewController and press "back" again it will crash)
It happens even with an empty ViewController (I tried to comment out all my code in ViewController.h and .m and to remove all the outlets links)
Nothing shows up in the debug console, only a EXEC_BAD_ACCESS is shown in main.m
I spent the afternoon on this and tried everything.
I don't include code right now because I have no idea where to look. As I said, it even happens with an empty ViewController.
Any thoughts or similar experience ?
EDIT:
Yes I tried to add an exception breakpoint
I even tried to find some observer issues with Spark debugger.
EDIT 2:
Actually, the ViewControllers were not that empty. The import on an UIView category was the problem. Check my answer below.
It's difficult to say exactly what could be causing it without more information, but in my experience the most common reason for an EXC_BAD_ACCESS is when someone tries to call a selector on a deallocated instance. This issue can be a lot easier to debug if you enable zombie objects.
Edit Scheme -> Diagnostics -> Enable Zombie Objects
Now instead of getting a bad access exception you should get a more helpful "message sent to deallocated instance" error (assuming that's actually the problem), along with what method was being called on which class of object.
The problem was that some of my views were importing a custom UIView category that included a dealloc method. I deleted the dealloc method from the category and everything is fine now.

Xcode incorrectly displaying the value of watch variables

I was scratching my head wondering why my rvc was set to nil when watching it while debugging through Xcode and thinking there must be something wrong with my project. So I created a project from scratch using the Xcode single view app template and then the only change I made was to add the following lines to didFinishLaunchingWithOptions:
Now look at what Xcode is displaying for the value of rvc in the watch window:
What's going on, why is it reporting rvc is nil?
Its not actually nil, but Xcode's watch window is reporting it as such. Is this a known issue with Xcode?
I found out the problem - its the positioning of the breakpoint, position it a line higher and rvc is not nil.
If you look at the watch window you can see rvc is light text when the other variables are bold text.
So my conclusion is at that point Xcode is reporting that rvc has gone out of scope and been deallocated, yet as the return statement has not yet executed at that point then rvc should not yet have gone out of scope.
Is it some Objective-C optimization thing going on resulting in this in Xcode or is it a defect with Xcode?
Either way its wasted a few hours of my time thinking I had a problem when there wasn't. In the future I need to make sure never to position breakpoints on a return statement again that contains local variables.

ios puzzle app crashes after a few rounds

I have an iPhone app, that seems to have memory leaking problem. It's a puzzle game, after a few puzzles, the app crashes on devices.
I'm now trying to use xcode Instruments to detect what's going on. First time to use Instruments.
I noticed a leak bar in the "Leaks" plot, right the time when the view is loaded:
What are these memory leaking objects, detected by xCode Instruments?
. However these leaked objects are small, so I guess my app has other problems.
When my app continues to run, usually for 10+ rounds on an iPad 2, it then crashes. I don't much about Instruments yet, so I watch "All Heap Allocations". At the beginning of first round puzzle, the column "# Overall" is ~70k, it grows slowly between rounds of puzzles. When a new round puzzle comes in, it goes to ~90k, then round by round it reaches ~200k, then crashes.
Before crashes, in the log console I see memory warning and "CONNECTION INTERRUPTED".
I've followed a few things after searching memory leaking, such set NSArray/NSDictionary or mutable ones to nil, as much as possible (although not all of them, since some go between puzzles). I also changed UIImage imageNamed to [UIIMage alloc] initWithContentOfFile.
What else should I look/check to see what causes memory problem? TIA!
EDIT:
I wish I could post some codes that may be the suspect, but I really don't know what part to post. I should've check via Instruments in the course developing, so that I would know what caused the problem.
Regarding other view controllers. I do have others (menu, settings, app-store-rate, etc) and I generated all of them via code. My app doesn't have a storyboard or nib file. When I test crashes, I just click Next Puzzle button, so all other views will not show at all. So, before crash, the only view shown is the main view, with a few button, a few subviews, an animated pictures (but only the first puzzle as introduction). If it helps, here is my app:
http://itunes.apple.com/us/app/wordsect/id599455449?ls=1&mt=8
If you trying to debug application with Instruments - enable zombie detection mode:
In
Xcode: Product->Scheme->Edit Scheme
Select Debug scheme
Select Arguments tab bar on the scheme description
In Environments variables add and check NSZombieEnabled variable
Then when you start application under Instruments control, you'll get name of the instance, when your application crashed.

How to use Admob Phonegap plugin with iOS

I'm using this Admob plugin for Phonegap running on iOS like this:
window.plugins.AdMob.createBanner({"siteId":"my-site-id"});
window.plugins.AdMob.loadBanner();
// move banner to make it appear
window.plugins.AdMob.moveBanner({"positionX":0,"positionY":410});
And it's actually working. The problem is that this is causing my app to consume a lot memory, and the app to crush when on a device according to the Apple crash report I got from iTunesConnect.
Can you help me in understanding how to use this plugin?
Thanks!
Are you using the deletBanner: method anywhere? I think there may be a memory leak there possibly. The plugin looks like it removes the adBanner property from its superview and nil's it out, but I think it may need to also:
Set the delegate for adBanner to nil
Release the adBanner (you can double-check this by seeing what the retain count of the adBanner is). I think UIViewController's dealloc automatically calls removeFromSuperView: but deleteBanner: probably wouldn't do that?

Resources