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
A memory leak is one of the major causes of the slowing down of a computer. It can be dangerous and lead to serious system stability issues. Check for driver updates and remove malware from the system, as it also can be the cause of memory leaks.
Memory leaks don't result in physical or permanent damage. Since it's a software issue, it will slow down the applications or even your whole system. However, a program taking up a lot of RAM space doesn't always mean its memory is leaking somewhere. The program you're using may really need that much space.
A memory leak starts when a program requests a chunk of memory from the operating system for itself and its data. As a program operates, it sometimes needs more memory and makes an additional request.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With