问题
I have an app which is crashing with
Terminating in response to backboardd's termination
Here the app crashes and even the Springboard. You can see the Apple logo for a short time and it seems that the device is rebooting.
This is taken from the device log
Incident Identifier: AECC8A4C-B6E0-47B5-A2DD-C3A367107087
CrashReporter Key: 26d2ecafff1bd02c1e774f056b3d20c8b03241c3
Hardware Model: iPad4,2
OS Version: iPhone OS 7.1.2 (11D257)
Kernel Version: Darwin Kernel Version 14.0.0: Thu May 15 23:17:54 PDT 2014; root:xnu-2423.10.71~1/RELEASE_ARM64_S5L8960X
Date: 2015-08-17 16:49:06 +0200
Time since snapshot: 117 ms
Free pages: 114466
Active pages: 5397
Inactive pages: 67177
Speculative pages: 258
Throttled pages: 0
Purgeable pages: 0
Wired pages: 52014
File-backed pages: 43687
Anonymous pages: 29145
Compressions: 4016283
Decompressions: 516269
Compressor Size: 10655
Uncompressed Pages in Compressor: 30459
Largest process: backboardd
Processes
Name <UUID> rpages recent_max fds [reason] (state)
CloudKeychainPro <0b4f59ba89df38039892ce8ad342a013> 152 152 100 (daemon) (idle)
syslog_relay <1dc57ae8a60c3654bbf327c16a01d551> 88 88 100 (daemon) (idle)
storebookkeeperd <83b2723af35f32b3beafb32abd677b7b> 509 509 100 (daemon) (idle)
adid <707928b1d97336d5beb5291562421efd> 130 130 200 (daemon) (idle)
aosnotifyd <6e3b66f6dad73af08e7f49db92efc045> 559 559 100 (daemon) (idle)
installd <4e0b7c36602737a3b0dd0bd733eb4378> 195 195 100 (daemon) (idle)
mobileassetd <8574a112afc337638edcd9ac0404f1c6> 1531 1531 200 (daemon) (idle)
gamed <943623c4259f306e93b97ce614edf89e> 785 785 100 (daemon) (idle)
afcd <208713527dc0315a9198e99db64d3cf1> 119 119 100 (daemon) (idle)
timed <294a840542e13dca88162e0fbe687f94> 244 244 100 (daemon) (idle)
keybagd <92fe9694044a3f4387459afb0f88a705> 114 114 100 (daemon) (idle)
MobileGestaltHel <f20bac36fcac32628ad30c2da33effd8> 161 161 100 (daemon) (idle)
geod <fb5d1b37f6703663818bd883ed500ea6> 263 263 100 (daemon) (idle)
softwareupdatese <5cfe93434a573beeb6ef41304af4a352> 949 949 200 (daemon) (idle)
assetsd <fd2bd931098b341f846302c614cc5ae8> 471 471 200 (daemon) (idle)
IMDPersistenceAg <9bd313f498a13e61b54d2ae6ec19ea2c> 220 220 100 (daemon) (idle)
accountsd <ee22a71a12f933179729608a16b45094> 622 622 100 (daemon) (idle)
itunesstored <3768d425f2103c209fdd1722b8f5acaa> 1171 1171 100 (daemon) (idle)
securityd <d79d9800981f3cedad0ca6975c9b9f0c> 602 602 100 (daemon) (idle)
mediaremoted <336797e58ac036298bdcdd5d558c227c> 245 245 100 (daemon) (idle)
coresymbolicatio <0b798227409d39c3b23e63bf4bcb820d> 89 89 100 (daemon) (idle)
DuetLST <06955a348ea2371e8d7ec43936431caa> 452 452 100 (daemon) (idle)
sandboxd <e75c30438fb73c20a67dd096f80352e3> 130 130 100 (daemon) (idle)
networkd_privile <5bd47a1c3d12302ea6d78a52cf4ab0a4> 90 90 100 (daemon) (idle)
routined <6dbb51d76fbb3d79aa6ea9f3c16c608f> 383 383 100 (daemon) (idle)
lsd <f2a08944163c31b9a8fd7f3a43ceacb0> 261 261 100 (daemon) (idle)
assistantd <5b53d51bff1236baa617758c37d4f862> 418 418 100 (daemon) (idle)
xpcd <8b704605eb243a10bfe026138c1908cd> 292 292 100 (daemon) (idle)
librariand <c8d851b111f0324e8de6eaf46ac108d0> 380 380 100 (daemon) (idle)
MobileMail <f359afe7da513629b0a6b8aa32a0b90b> 1073 1073 100 (resume) (continuous)
tccd <e37a9bd3403c34adbbd9d75e9022240a> 179 179 100 (daemon)
kbd <2669fa0ab11a356fbd9482881637e730> 595 595 100 (daemon)
MyCrashingApp <25870f37b79d36e584a2e7c6db2717f5> 176783 176783 100 [per-process-limit] (frontmost) (resume)
ptpd <606d697050af3b23a54e4d75eafef6c0> 605 605 200 (daemon)
identityservices <1695cbd72da83c4c87c568bd53a01d24> 442 442 200 (daemon)
wifid <c0ed3dbc8d7f329489a04faf460c027c> 411 411 200 (daemon)
syslogd <88667a0c3dc6398e9b1c6a0c5a5d8f24> 187 187 200 (daemon)
powerd <1a8551a962783aa9899be0e55a9c1e58> 152 152 200 (daemon)
locationd <3480b01585f039ca9c45ecc16928d8b0> 1139 1139 200 (daemon)
imagent <5a1a726d45e033f2bea34c3ae04e817c> 300 300 200 (daemon)
dataaccessd <ae41b26410e3338ba33e337fb5439069> 1131 1131 100 (daemon)
apsd <f96e01aab90637b0822aff105bf78d70> 578 578 200 (daemon)
mediaserverd <6c2cee9548813cea95bf5548d3411408> 1087 1087 100 (daemon)
iaptransportd <009cdd0e53bf34829b6a8b69e0ca49bf> 260 260 200 (daemon)
mDNSResponder <090a345fd6e13f52b156a3eb9a0e78ee> 220 220 100 (daemon)
sharingd <63eae5785eac326987c89d771258ebf8> 571 571 200 (daemon)
SpringBoard <ccb584e84f2f3005a9c20897fdb783dd> 6419 6419 100
backboardd <3085386f5f99357aa9f055e0fb79b827> 181876 181876 100 [per-process-limit] (daemon)
fseventsd <8b8df4c7b46b3dcfb4e1b1d8a6cbb686> 1203 1203 50 (daemon)
lockdownd <6bdd33b3920236808292915812d386c8> 344 344 50 (daemon)
wirelessproxd <41e0cf822ff33124b3c3949cedce7fd2> 196 196 50 (daemon)
configd <2123dc8c1e103375aec0905809a8d38e> 646 646 50 (daemon)
aggregated <178824f7adc231249e9e341c03c36855> 590 590 100 (daemon)
fairplayd.A2 <9948545906083ff9962c310943eb34de> 148 148 100 (daemon)
BTServer <5540f7e4ecd535b9a48b50258130dbd1> 404 404 100 (daemon)
distnoted <a237d6a85cae3c409b914ccb8e5b63f1> 182 182 100 (daemon)
UserEventAgent <f9cb9c166628392a9d190acff16950b9> 995 995 100 (daemon)
filecoordination <4d26113e2e3d3b21832eb866679edf38> 251 251 200 (daemon)
itunescloudd <266cb30204a039d5b2f5aba30cf05015> 1044 1044 100 (daemon)
DTPower <79ced86c61333b6aaa2460276eb0b8eb> 282 282 200 (daemon)
ubd <b54681e3319e36b48148ab2026ebf542> 655 655 200 (daemon)
eapolclient <a5ac733ff23936b4ab05dde3fd5fb17b> 173 173 50 (daemon)
afcd <208713527dc0315a9198e99db64d3cf1> 134 134 200 (daemon)
notification_pro <293150329f1d317c99a6c5fa2e25963a> 140 140 200 (daemon)
DTMobileIS <100bfdacf0a63ae9ab08b27669042812> 2292 2292 200 (daemon)
LeakAgent <30856ea2089a3263aaf27fd9faee406d> 3520 3520 100 (daemon)
networkd <7262086478d63812ae40c561e8e1acbf> 509 509 200 (daemon)
WirelessCoexMana <1e096a90f671399d975e83beb668eb91> 151 151 100 (daemon)
touchsetupd <9d37501e59f13ca1b1577435bdb43a9f> 197 197 200 (daemon)
CommCenter <e5c6b5b1f64833de93bd22bbe135c9b6> 1196 1196 100 (daemon)
notifyd <1d555aa3d08c336294a38d9c134dca00> 319 319 100 (daemon)
**End**
I can't see any hint where the problem lies. The app crashes when I push a new view controller on the navigation stack. On this view controller there is a full screen label. The error also happens after opening and closing the view controller 40 times or so.
Similar questions have different hints:
- Too much memory from OS requested
- Too many animations/didn't queue animations
- Use instruments
- Memory warning
So the memory management problem is the most likely one. I tried to use Instruments, but Leaks didn't give me some useful hints (only some malloc and auto release pool with 48 kB max. - seems a OS bug). Also Zombies and Activity Monitor aren't helpful. Using Instruments makes everything really slow.
Only with allocations I saw the UILabel
subclass is taking too much space. Every time the new view controller is created, the memory increases by 10 MB (persistent bytes) and that is only the label!
Too make things more complex I'm using Xamarin.iOS. The garbage collector isn't deallocating the view controller when it popped off the navigation controller. But it does it at some time. I think when the system needs more space (nothing left) than the GC kicks in. I could reproduce this behavior in a simple project with my big sized label.
Why does the garbage collector doesn't kick in? I get memory warnings but I can't release something. Normally the view controller and its subviews should get deallocated when they are unloaded from the navigation controller.
When I know why my app is crashing I can do something against this. How can I debug this issue?
Edit:
Now I tried to crash the app on an iPhone. Here you can find the debugger output and here the device log. Again it seems that I'm running out of memory. But my only hint is still the label, because none of the tools can tell me exactly where the problem lies.
回答1:
I made the following steps to reduce the memory pressure:
- used separate class for my custom
EventArgs
(before: in view controller) - no anonymous function for button in
UINavigationBar
- no anonymous funciton for
UIActionSheet
- rewrote
EventHandler
in that way that I subscribe to them inviewWillAppear
and unsubscribe inviewWillDisappear
(most of the time) - added
Target
forUIGestureRecognizer
inviewWillAppear
and removed it inviewWillDisappear
- removed cycle between view controller and datasource through using a
WeakReference
I made some checks and it now seems to work. For testing if a view controller is deallocated or not use this:
protected override void Dispose (bool disposing)
{
Console.WriteLine (String.Format ("{0} controller disposed - {1}",
this.GetType (), this.GetHashCode ()));
base.Dispose (disposing);
}
Through this and commenting the things out I were able to detect the reference cycles. I hope I fixed all problems. The main problems were the EventHandler
.
For solving my issue the following questions belong to it:
- Clicked handler not executed for UIButton in UIBarButtonItem
- How to break reference cycle between view controller and data source
- Through presenting new view controller viewWillDisappear on parent is triggered where I unsubscribe from the events
- RemoveTarget from UITapGestureRecognizer
- Add/remove EventHandler for UIBarButtonItem
The following links were helpful in resolving the memory issue:
- Memory and Performance Best Practices
- Is this a bug in MonoTouch GC?
- Memory Management Pitfalls in Xamarin iOS - Introduction + Part 1 + Part 2
- Weak Event Pattern in MonoTouch
- iOS Memory Managment by Rodrigo Kumpera (Xamarin)
- My App Crashed, Now What? – Part 1 + Part 2
- signal
来源:https://stackoverflow.com/questions/32053817/app-ios-crashes-with-terminating-in-response-to-backboardds-termination