Custom KeyBoard Ends Due to Memory Pressure in iOS 8

Custom KeyBoard Ends Due to Memory Pressure in iOS 8

Initially, my user keyboard takes up about 25 MB of memory, but this memory is not freed, and I skip the keyboard. Memory continues to grow when we open the user keyboard over and over and finally end up due to memory pressure.

Help me with this problem?

+8
memory iphone keyboard ios8-extension
source share
3 answers

You can disable some functions in the ViewWillDisappear KeyboardViewController function

+1
source share

Keyboard expansion is performed in a process that persists after the keyboard disappears. The controller of your keyboard controller is re-created each time your keyboard is created, but the process in which the view controller is located is saved. Thus, free memory when your view controller is closed. If you use images, you will not want to use imageNamed: you will want to use imageWithContentsOfFile :. Because UIImage uses a cache for imageNamed, which will be preserved.

+1
source share

I tried many ways to avoid this known memory accumulation problem, but according to my long lengthy trial version and errors, the best and easiest way to free all memory before the keyboard disappears is to call exit(0) in viewWillDisappear of KeyboardViewController .

 - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; exit(0); } 

[Refresh] exit(0) ideal for releasing all memory, as it kills the keyboard expansion process. Unfortunately, it seems that killing the process makes iOS unstable.
Therefore, the most stable way is to free all selected objects as much as possible in viewWillDisappear . For example,

For all user views and all custom view controllers

  • Remove all strong links to views and view controllers, such as subviews, constraints, gestures, strong delegate, etc.

     [aView removeFromSuperview]; [aView removeConstraints:aView.constraints]; for (UIGestureRecognizer *recognizer in aView.gestureRecognizers) [aView removeGestureRecognizer:recognizer]; 
  • Set nil for all properties of the view controller object.

     aViewController.anObject = nil; 

For other large custom objects

  • Remove all added objects from all arrays, dictionaries, etc.

     [anArray removeAllObjects]; 
  • Do not cache images using imageNamed:

If well released, memory usage during debugging will not be increased or slightly increased (<0.1MBytes per termination). If memory usage increases after many layoffs, even though user objects have been released as much as possible, exit (0), you can periodically call with some risk of unloading.

+1
source share

All Articles