From 37f133df0fb353312b3ff2985b1a746a030bc6ce Mon Sep 17 00:00:00 2001 From: Hein Rutjes Date: Fri, 24 Jul 2020 15:51:27 +0200 Subject: [PATCH] [expo-av] Fix mem-leak when unmounting Video component (#9379) * [expo-av] Fix mem-leak when unmounting Video view * [expo-av] Clean-up unused observers * [expo-av] Update changelog --- packages/expo-av/CHANGELOG.md | 1 + packages/expo-av/ios/EXAV/EXAV.m | 4 ++-- packages/expo-av/ios/EXAV/Video/EXVideoView.m | 2 -- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/expo-av/CHANGELOG.md b/packages/expo-av/CHANGELOG.md index 3ac88cd69a4c7..872e108233c97 100644 --- a/packages/expo-av/CHANGELOG.md +++ b/packages/expo-av/CHANGELOG.md @@ -13,6 +13,7 @@ - Prevent debugger break when removing observations. ([#9334](https://github.com/expo/expo/pull/9334) by [@IjzerenHein](https://github.com/IjzerenHein)) - Fix iOS stability issue due to player-item observers not cleaned up. ([#9350](https://github.com/expo/expo/pull/9350) by [@IjzerenHein](https://github.com/IjzerenHein)) - Fix duplicate full-screen will-dismiss event on iOS. ([#9366](https://github.com/expo/expo/pull/9366) by [@IjzerenHein](https://github.com/IjzerenHein)) +- Fix mem-leak when unmounting Video component. ([#9379](https://github.com/expo/expo/pull/9379) by [@IjzerenHein](https://github.com/IjzerenHein)) - De-activate audio-session after unloading sound. ([#9365](https://github.com/expo/expo/pull/9365) by [@IjzerenHein](https://github.com/IjzerenHein)) - Fix resume audio when in background. ([#9363](https://github.com/expo/expo/pull/9363) by [@IjzerenHein](https://github.com/IjzerenHein)) - Fix instability issues when changing source and useNativeControls. ([#9381](https://github.com/expo/expo/pull/9381) by [@IjzerenHein](https://github.com/IjzerenHein)) diff --git a/packages/expo-av/ios/EXAV/EXAV.m b/packages/expo-av/ios/EXAV/EXAV.m index 904dddcdc3ac2..017862e390583 100644 --- a/packages/expo-av/ios/EXAV/EXAV.m +++ b/packages/expo-av/ios/EXAV/EXAV.m @@ -46,7 +46,7 @@ @interface EXAV () @property (nonatomic, assign) int soundDictionaryKeyCount; @property (nonatomic, strong) NSMutableDictionary *soundDictionary; @property (nonatomic, assign) BOOL isBeingObserved; -@property (nonatomic, strong) NSMutableSet *> *videoSet; +@property (nonatomic, strong) NSHashTable *> *videoSet; @property (nonatomic, strong) NSString *audioRecorderFilename; @property (nonatomic, strong) NSDictionary *audioRecorderSettings; @@ -79,7 +79,7 @@ - (instancetype)init _soundDictionaryKeyCount = 0; _soundDictionary = [NSMutableDictionary new]; _isBeingObserved = NO; - _videoSet = [NSMutableSet new]; + _videoSet = [NSHashTable weakObjectsHashTable]; _audioRecorderFilename = nil; _audioRecorderSettings = nil; diff --git a/packages/expo-av/ios/EXAV/Video/EXVideoView.m b/packages/expo-av/ios/EXAV/Video/EXVideoView.m index 33d1ab23ac58f..07dc27ad58be2 100644 --- a/packages/expo-av/ios/EXAV/Video/EXVideoView.m +++ b/packages/expo-av/ios/EXAV/Video/EXVideoView.m @@ -634,7 +634,6 @@ - (void)removeFromSuperview { [self _removeData]; [self _removePlayer]; - [[NSNotificationCenter defaultCenter] removeObserver:self]; [super removeFromSuperview]; } @@ -743,7 +742,6 @@ - (void)handleMediaServicesReset:(void (^)(void))finishCallback - (void)dealloc { [_exAV unregisterVideoForAudioLifecycle:self]; - [[NSNotificationCenter defaultCenter] removeObserver:self]; [_data pauseImmediately]; [_exAV demoteAudioSessionIfPossible]; }