I am building a custom keyboard extension (iOS 9+) and have found a more than annoying memory leak.
When leaving an application (in this test case the Messages app) then returning, this leak occurs. Typically(seen in the photos of Xcode's Instruments7 below)
I have literally done nothing to the template but receive this leak. Does anyone have any suggestions on how to fix this?...
For fun, here's a screen shot of the glorious leak... AND first a snippet of my complex VC.... 😂
This is after tapping a text field, dismissing the controller, then tapping the field again
(show -> hide -> show)
#import "KeyboardViewController.h"
@implementation KeyboardViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
@end
As much as I would like to have awarded the bounty to a solution, not the only answer I received... the answer to this really ended up being "Oops I'm not doing anything wrong...".
After having done way too deep of a dive investigating what really is causing these leaks (14 total after literally removing everything except the view controller's instance), I discovered the true culprit.
Apple.
Even when I remove ALL code, literally leaving only the following
- (void)viewDidLoad {
[super viewDidLoad];
// Great...
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// Super!
}
...I still get 14 leaks, all of which are sprung from UIKit
, Foundation
, and CoreFoundation
. Basically, if I removed anything else from the process, there would be no process, as nothing would be happening. Who knows...maybe the leak would still be there then too..
Nevertheless, thankfully this leak does NOT crush the memory allocation unless you intend to perhaps type a message for a few years straight. It also does not appear to worsen from anything else in my code, so besides it being a terribly ugly bug, my conclusion is that it's A OK.
Thanks Apple!