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.
Neonberry
source share