Description
When calling [FFmpegKitConfig clearSessions]
, only the sessionHistoryList
is emptied, leaving sessionHistoryMap
to leak and retain a reference to the FFmpegSession
.
Sessions history list and map are added at https://github.com/tanersener/ffmpeg-kit/blob/5d11e79fc2734a7c61b741f3a729409a17b212e1/apple/src/FFmpegKitConfig.m#L115
Notably, if you are using session execute callbacks , ffmpeg-kit will continue to leak FFmpegSession
objects, even if you set [FFmpegKitConfig setSessionHistorySize:0]
. I've noticed this behaviour in previous versions but didn't investigate further at the time and was happy enough to use the global callbacks. My use-case has shifted and I have concurrent ffmpeg sessions running for my application, so I took a further look. This affects asynchronous commands issued on another queue. lldb will not be able to point out any obvious leaks here.
As a test, I issued a sample command to + (FFmpegSession*)executeAsync:(NSString*)command withExecuteCallback:(ExecuteCallback)executeCallback withLogCallback:(LogCallback)logCallback withStatisticsCallback:(StatisticsCallback)statisticsCallback onDispatchQueue:(dispatch_queue_t)queue
with non-null, empty blocks. I monitored and waited for the autoreleasepool and took some samples after successful return.
Here's the situation without calling the newly added [FFmpegKitConfig clearSessions]
:
and if you do decide to clear the session list:
Only if ([sessionHistoryList count] > sessionHistorySize)
are entries removed when adding a new session. This means at least 1 session will always linger and leak, replacing the previous reference.
Based off this commit, I added a method call to clear out sessionHistoryMap
. I can confirm that in my use-case, my leaks disappear once I call [FFmpegKitConfig clearSessions]
.
Environment
Platform: [macOS]
Architecture: [x86_64]
Version [v4.5]
Source branch [master, v4.5]
Xcode version [13.0]