Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS app being killed (jettisoned) by mediaserverd memory issue (leak?) while streaming video

We are seeing a strange crash in which it appears that iOS is jettisoning our app along with mediaserverd after receiving a level 2 memory warning. It occurs while streaming DRM content (including, but not limited to, PlayReady encrypted content) about 7-8 minutes into playback - even if we have restarted the device with no other applications running in the background. This does not happen consistently, however, and we can sometimes complete the same piece of content (an entire 2 hour movie) with numerous memory-heavy applications in the background without any issues.

We are seeing this on iPhone 3GS, 4, and 4S devices running iOS 5.1 and 5.1.1, though it appears to be most prominent on a 3GS. The app is be terminated with either "segmentation fault 11" or "signal 9". Segmentation fault 11 can refer to bad memory access or low memory and signal 9 refers to low memory termination.

We have used both the static analyzer and instruments to find and fix any leaks and nothing alarming shows up in the Leaks instrument.

When analyzing playback using the Memory Monitor instrument, we see a dramatic decrease in available physical memory when we begin streaming, which is to be expected to a certain extent. When the application/os is behaving normally, other applications are removed from the background when memory becomes too low, but occasionally the available physical memory will simply continue to drop until the OS kills our app. No crash logs are generated, although we occasionally receive Low Memory logs, like the one below:

Incident Identifier: 13839D5B-D280-40D8-8C67-6EE3D61394C3
CrashReporter Key:   d3746ff556543d6a94e067d82c8fb379a285f543
Hardware Model:      iPhone2,1
OS Version:          iPhone OS 5.1.1 (9B206)
Kernel Version:      Darwin Kernel Version 11.0.0: Sun Apr  8 21:50:49 PDT
2012; root:xnu-1878.11.10~1/RELEASE_ARM_S5L8920X
Date:                2012-06-28 14:09:56 -0400
Time since snapshot: 104 ms

Free pages:        712
Active pages:      1433
Inactive pages:    1012
Throttled pages:   49925
Purgeable pages:   0
Wired pages:       11870
Largest process:   SpringBoard

Processes
         Name                 UUID                    Count resident pages
         launchd <5fec01c378a030a8bd23062689abb07f>      79
securekeyvaultd. <78f602d3604c3bf487a27a288dec3bbb>     156
           MYAPP <285e46965a91381dad0661443c8be3eb>    4035 (jettisoned) (active)
     MobilePhone <8f3f3e982d9235acbff1e33881b0eb13>     749 (jettisoned)
    mediaserverd <f03b746f09293fd39a6079c135e7ed00>    3670 (jettisoned)
        networkd <80ba40030462385085b5b7e47601d48d>     145
            apsd <e7a29f2034083510b5439c0fb5de7ef1>     260
     SpringBoard <c74dc89dec1c3392b3f7ac891869644a>    4615 (active)
         notifyd <f6a9aa19d33c3962aad3a77571017958>     170
        BTServer <31e82dfa7ccd364fb8fcc650f6194790>     259
CommCenterClassi <041d4491826e3c6b911943eddf6aaac9>     421
      aggregated <a12fa71e6997362c83e0c23d8b4eb5b7>     329
         configd <ee72b01d85c33a24b3548fa40fbe519c>     324
   fairplayd.N88 <ecb9495b29543b35a1f2e6c2b432528c>     168
       fseventsd <914b28fa8f8a362fabcc47294380c81c>     164
            iapd <0a747292a113307abb17216274976be5>     284
         imagent <9c3a4f75d1303349a53fc6555ea25cd7>     412
       locationd <cf31b0cddd2d3791a2bfcd6033c99045>     493
   mDNSResponder <86ccd4633a6c3c7caf44f51ce4aca96d>     182
    mediaremoted <327f00bfc10b3820b4a74b9666b0c758>     208
       lockdownd <b06de06b9f6939d3afc607b968841ab9>     315
          powerd <133b7397f5603cf8bef209d4172d6c39>     143
         syslogd <7153b590e0353520a19b74a14654eaaa>      90
           wifid <3001cd0a61fe357d95f170247e5458f5>     285
  UserEventAgent <dc32e6824fd33bf189b266102751314f>     322
         launchd <5fec01c378a030a8bd23062689abb07f>     120

End

According to some older questions I've seen on here, it seems that mediaserverd used to have serious problems with memory leaks in previous versions of iOS.

Could this be related to the issue?

How can we prevent this from happening?

Any ideas, theories, feedback, or similar issues would be greatly appreciated!

like image 495
Kevin James Hunt Avatar asked Aug 07 '12 17:08

Kevin James Hunt


1 Answers

This is just a blind guess, but aren't you using AVFoundation's AVPlayer? I had an issue like this, it turned out I wasn't releasing AVPlayers correctly. So for every song I created a new AVPlayer, which is fine if you release the old, but I didn't. I found it out by doing an allocation test in Instruments and saw AVPlayers remain living after they supposed to be released.

like image 199
Skrew Avatar answered Nov 08 '22 00:11

Skrew