0

My app uses NSTimer variable which uses NSNotificationCenter.postNotificationName to post notification to UIViewController class every seconds.

The issue is the app crashes once in a while with no stacktrace which mean it is a memory issue.

From Instruments, it happens because a 1.78MB increase in VM:Allocation. The allocation just happens randomly.

Here is right after I start the timer: enter image description here

Here is when I start the timer for a few minutes enter image description here So,

  1. I don't see stacktrace or anything. How do I go about debugging this?

  2. The app use only 7.3MB and is in the foreground, why does it get kill?? :(

  3. I just leave the timer running, the method only updating existing variables, what trigger this VM:Allocation???

I use Swift, if that matters

Thanks,

Motoko
  • 1,062
  • 2
  • 15
  • 32

1 Answers1

0

Turn out the problem is in the for loop. I had a big for loop that do a lot of assignment, calling API, etc, every time the NSTimer function is called so sometime when the number of iterations are a little bit too high the VM Allocation kicks in.

The answer I believe is to use autoreleasepool {} inside the for loop. No crash has happens ever since. Watching these WWDC2013 video helps a bit in term of ideas but not directly.

Improving Your App with Instruments

Intermediate Swift

Motoko
  • 1,062
  • 2
  • 15
  • 32