title: iOS app being killed (jettisoned) by mediaserverd memory issue (leak?) while streaming video
body: <p>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.  </p>
  
  <p>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.</p>
  
  <p>We have used both the static analyzer and instruments to find and fix any leaks and nothing alarming shows up in the Leaks instrument.</p>
  
  <p>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:</p>
  
  <pre><code>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 &lt;5fec01c378a030a8bd23062689abb07f&gt;      79
  securekeyvaultd. &lt;78f602d3604c3bf487a27a288dec3bbb&gt;     156
             MYAPP &lt;285e46965a91381dad0661443c8be3eb&gt;    4035 (jettisoned) (active)
       MobilePhone &lt;8f3f3e982d9235acbff1e33881b0eb13&gt;     749 (jettisoned)
      mediaserverd &lt;f03b746f09293fd39a6079c135e7ed00&gt;    3670 (jettisoned)
          networkd &lt;80ba40030462385085b5b7e47601d48d&gt;     145
              apsd &lt;e7a29f2034083510b5439c0fb5de7ef1&gt;     260
       SpringBoard &lt;c74dc89dec1c3392b3f7ac891869644a&gt;    4615 (active)
           notifyd &lt;f6a9aa19d33c3962aad3a77571017958&gt;     170
          BTServer &lt;31e82dfa7ccd364fb8fcc650f6194790&gt;     259
  CommCenterClassi &lt;041d4491826e3c6b911943eddf6aaac9&gt;     421
        aggregated &lt;a12fa71e6997362c83e0c23d8b4eb5b7&gt;     329
           configd &lt;ee72b01d85c33a24b3548fa40fbe519c&gt;     324
     fairplayd.N88 &lt;ecb9495b29543b35a1f2e6c2b432528c&gt;     168
         fseventsd &lt;914b28fa8f8a362fabcc47294380c81c&gt;     164
              iapd &lt;0a747292a113307abb17216274976be5&gt;     284
           imagent &lt;9c3a4f75d1303349a53fc6555ea25cd7&gt;     412
         locationd &lt;cf31b0cddd2d3791a2bfcd6033c99045&gt;     493
     mDNSResponder &lt;86ccd4633a6c3c7caf44f51ce4aca96d&gt;     182
      mediaremoted &lt;327f00bfc10b3820b4a74b9666b0c758&gt;     208
         lockdownd &lt;b06de06b9f6939d3afc607b968841ab9&gt;     315
            powerd &lt;133b7397f5603cf8bef209d4172d6c39&gt;     143
           syslogd &lt;7153b590e0353520a19b74a14654eaaa&gt;      90
             wifid &lt;3001cd0a61fe357d95f170247e5458f5&gt;     285
    UserEventAgent &lt;dc32e6824fd33bf189b266102751314f&gt;     322
           launchd &lt;5fec01c378a030a8bd23062689abb07f&gt;     120
  
  End
  </code></pre>
  
  <p>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.  </p>
  
  <p>Could this be related to the issue?  </p>
  
  <p>How can we prevent this from happening?</p>
  
  <p>Any ideas, theories, feedback, or similar issues would be greatly appreciated!</p>