Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keyboard Extension Memory Leak?

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?...

UPDATE

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

enter image description here

like image 831
Will Von Ullrich Avatar asked Dec 15 '17 18:12

Will Von Ullrich


People also ask

Is memory leak serious?

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.

Do memory leaks cause permanent damage?

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.

What is the main cause of memory leaks?

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.


1 Answers

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!

like image 172
Will Von Ullrich Avatar answered Oct 17 '22 00:10

Will Von Ullrich