diff --git a/Firestore/Source/Local/FSTLRUGarbageCollector.mm b/Firestore/Source/Local/FSTLRUGarbageCollector.mm index 31919a375d0..cc368fd3f8f 100644 --- a/Firestore/Source/Local/FSTLRUGarbageCollector.mm +++ b/Firestore/Source/Local/FSTLRUGarbageCollector.mm @@ -81,7 +81,7 @@ size_t size() const { }; @implementation FSTLRUGarbageCollector { - id _delegate; + __weak id _delegate; LruParams _params; } diff --git a/Firestore/Source/Local/FSTLevelDBMutationQueue.mm b/Firestore/Source/Local/FSTLevelDBMutationQueue.mm index 2fc941478ff..f28ba386051 100644 --- a/Firestore/Source/Local/FSTLevelDBMutationQueue.mm +++ b/Firestore/Source/Local/FSTLevelDBMutationQueue.mm @@ -86,7 +86,8 @@ - (instancetype)initWithUserID:(std::string)userID @end @implementation FSTLevelDBMutationQueue { - FSTLevelDB *_db; + // This instance is owned by FSTLevelDB; avoid a retain cycle. + __weak FSTLevelDB *_db; /** The normalized userID (e.g. nil UID => @"" userID) used in our LevelDB keys. */ std::string _userID; diff --git a/Firestore/Source/Local/FSTLevelDBQueryCache.mm b/Firestore/Source/Local/FSTLevelDBQueryCache.mm index 216ebce85a1..a1309edef9b 100644 --- a/Firestore/Source/Local/FSTLevelDBQueryCache.mm +++ b/Firestore/Source/Local/FSTLevelDBQueryCache.mm @@ -62,7 +62,8 @@ @interface FSTLevelDBQueryCache () @end @implementation FSTLevelDBQueryCache { - FSTLevelDB *_db; + // This instance is owned by FSTLevelDB; avoid a retain cycle. + __weak FSTLevelDB *_db; /** * The last received snapshot version. This is part of `metadata` but we store it separately to diff --git a/Firestore/core/src/firebase/firestore/remote/connectivity_monitor_apple.mm b/Firestore/core/src/firebase/firestore/remote/connectivity_monitor_apple.mm index 558b963536c..f77a3310283 100644 --- a/Firestore/core/src/firebase/firestore/remote/connectivity_monitor_apple.mm +++ b/Firestore/core/src/firebase/firestore/remote/connectivity_monitor_apple.mm @@ -77,7 +77,13 @@ void OnReachabilityChangedCallback(SCNetworkReachabilityRef /*unused*/, class ConnectivityMonitorApple : public ConnectivityMonitor { public: explicit ConnectivityMonitorApple(AsyncQueue* worker_queue) - : ConnectivityMonitor{worker_queue}, reachability_{CreateReachability()} { + : ConnectivityMonitor{worker_queue} { + reachability_ = CreateReachability(); + if (!reachability_) { + LOG_DEBUG("Failed to create reachability monitor."); + return; + } + SCNetworkReachabilityFlags flags; if (SCNetworkReachabilityGetFlags(reachability_, &flags)) { SetInitialStatus(ToNetworkStatus(flags)); @@ -108,10 +114,14 @@ explicit ConnectivityMonitorApple(AsyncQueue* worker_queue) } ~ConnectivityMonitorApple() { - bool success = - SCNetworkReachabilitySetDispatchQueue(reachability_, nullptr); - if (!success) { - LOG_DEBUG("Couldn't unset reachability queue"); + if (reachability_) { + bool success = + SCNetworkReachabilitySetDispatchQueue(reachability_, nullptr); + if (!success) { + LOG_DEBUG("Couldn't unset reachability queue"); + } + + CFRelease(reachability_); } } @@ -121,7 +131,7 @@ void OnReachabilityChanged(SCNetworkReachabilityFlags flags) { } private: - SCNetworkReachabilityRef reachability_; + SCNetworkReachabilityRef reachability_ = nil; }; namespace { diff --git a/Firestore/core/src/firebase/firestore/remote/remote_objc_bridge.h b/Firestore/core/src/firebase/firestore/remote/remote_objc_bridge.h index 1ba7e347aef..8c7cbb951ba 100644 --- a/Firestore/core/src/firebase/firestore/remote/remote_objc_bridge.h +++ b/Firestore/core/src/firebase/firestore/remote/remote_objc_bridge.h @@ -185,7 +185,7 @@ class WatchStreamDelegate { void NotifyDelegateOnClose(const util::Status& status); private: - id delegate_; + __weak id delegate_; }; /** A C++ bridge that invokes methods on an `FSTWriteStreamDelegate`. */ @@ -202,7 +202,7 @@ class WriteStreamDelegate { void NotifyDelegateOnClose(const util::Status& status); private: - id delegate_; + __weak id delegate_; }; } // namespace bridge