Process replayd killed by jetsam reason highwater

Recently I add a broadcast upload extension to my host app to implement system wide screen cast.I found the broadcast upload extension sometimes stopped for unknown reason.If I debug the broadcast upload extension process in Xcode, it stopped without stopping at a breakpoint(If the extension is killed for 50M bytes memory limit, it will stopped at a breakpoint, and Xcode will point out that it's killed for 50M bytes memory limit).For more imformation, I read the console log line by line.Finally, I found a significant line:

osanalyticshelper Process replayd [26715] killed by jetsam reason highwater

It looks like the ReplayKit serving process 'replayd' is killed by jetsam, and the reason is 'highwater'.So I searched the internet for more imformation.And I found a post:

https://www.jianshu.com/p/30f24bb91222

After reading that,I checked the JetsamEvent report in device, and found that when the 'replayd' process was killed it occupied 100M bytes memory.Is there a 100M bytes memory limit for 'replayd' process?How can I avoid it to occupy more than 100M bytes memory?

Further more, I found that this problem offen occured if the previous extension process is stopped via RPBroadcastSampleHandler's finishBroadcastWithError method.If I stop the extension via control center button, this rarely occured.

As comparison, when the 'Wemeet' app stop it's broadcast upload extension, it raraly cause this problem.I compared the console log when 'Wemeet' stop it's broadcast extension and the log my app stop it's broadcast extension.I found this line is different:

Wemeet: mediaserverd MEDeviceStreamClient.cpp:429 AQME Default-InputOutput: client stopping: <ZenAQIONodeClient@0x1080f7a40, sid:0x3456e, replayd(30213), 'prim'>; running count now 0

My app: mediaserverd MEDeviceStreamClient.cpp:429 AQME Default-InputOutput: client stopping: <ZenAQIONodeClient@0x107e869a0, sid:0x3464b, replayd(30232), 'prim'>; running count now 3

As we can see, the 'running count' is different.

I found the problem through 'Activity Monitor' of 'Instruments' tool from xcode.

It seems that the system process 'replayd' has a 20MB~30MB memory leaked when finish broadcasting through RPBroadcastSampleHandler's finishBroadcastWithError method.

There is no such memory leak when stop the extension via control center button.

The iOS 13 upto the latest version of iOS have the same issue.

When App begin and finish broadcasting many times, the memory usage of 'replayd' background process is glow.

The 'replayd' background process may killed by jetsam highwater because of OOM memory status checking during broadcasting and cause stop broadcasting unexpectedly.

Process replayd killed by jetsam reason highwater
 
 
Q