IOS app crashes after returning from the background, but not before?

I have a strange situation. I have a fairly intensive image processing process (image processing), but I developed all the kinks and it only works 99% of the time.

However, if I put the application in an inactive or background state, when I return and try to start the same process, I get warnings about memory, and then the application crashes.

I used tools for analyzing the memory area in two use cases, and the amount of memory is exactly the same. However, in the case when I do not put the application in the background (or inactive), it does not give me any memory errors and finishes fine. In case of use, when it was put in the background (or inactive), I get memory errors and crash.

Does anyone have any info on this? I combed net / irc / stack over / apple docs trying to figure this out. Is apple (iOS) a decrease in the amount of memory that my application can run after I return from the background? Is there any way to prevent this? Or do I not see another simpler solution?

(Please note that there are no memory leaks)

+6
source share
3 answers

Well, I realized that iOS isn’t doing anything stupid, this is, of course, the developer :) There was another component in my project (ViewController) that did some things when it returned from the background, for example, allocating memory. However, this idea was not active, so the allocation of the memory he needed was useless. After clearing the code, I did not encounter memory errors.

+2
source

Just for verification, when starting any background process, it should be in the autorun pool. Background processes run in parallel with the main thread. Therefore, performing any task in the background, we must look at the memory. This is a common mistake often encountered for leakage. Also, operations related to UIKit are always performed in the main thread. Therefore, if you process any data using the background and want to display it in the user interface, then this will be loaded into the main stream.

+2
source

Your application may receive warnings about memory in the background, and your answers to this are different: for example, in the background all view controllers can unload their contents when they receive a memory warning, but in the foreground the active view controller will not be unloaded. You can send messages to freed instances if, say, a view controller or one of its objects is set up as a delegate to some other process in your application that does not respond to low memory warnings.

If you know the details of the crashes that you really need to enable, and more about the structure of the application, this is my best guess.

0
source

Source: https://habr.com/ru/post/907001/


All Articles