[GH-ISSUE #604] Memory leak in OAuthSwift: Observer is not cleared out #392

Closed
opened 2026-03-03 16:48:19 +03:00 by kerem · 0 comments
Owner

Originally created by @vgritsenko on GitHub (Jun 16, 2020).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/604

Description:

There is a memory leak in OAuthSwift. Observer which is registered with notification center in observeCallback(_:) is saved to self.observer property, and when this observer is removed later in removeCallbackNotificationObserver(), the self.observer is never cleared out, keeping observation block in memory, thus keeping the block passed in as an argument to observeCallback in memory, and everything that block refers to.

diff --git a/Pods/OAuthSwift/Sources/OAuthSwift.swift b/Pods/OAuthSwift/Sources/OAuthSwift.swift
index 07ea49851..902f0e550 100644
--- a/Pods/OAuthSwift/Sources/OAuthSwift.swift
+++ b/Pods/OAuthSwift/Sources/OAuthSwift.swift
@@ -67,6 +67,7 @@ open class OAuthSwift: NSObject, OAuthSwiftRequestHandle {
     public func removeCallbackNotificationObserver() {
         if let observer = self.observer {
             OAuthSwift.notificationCenter.removeObserver(observer)
+            self.observer = nil
         }
     }

OAuth Provider? (Twitter, Github, ..):

Facebook, Google, any other.

OAuth Version:

  • Version 1
  • Version 2

OS (Please fill the version) :

  • iOS : All versions
  • OSX :
  • TVOS :
  • WatchOS :

Installation method:

  • Carthage
  • CocoaPods
  • Swift Package Manager
  • Manually

Library version:

  • head
  • v2.1.0
  • v2.0.0
  • v1.4.1
  • other: (Please fill in the version you are using.)

Xcode version:

  • 11.4 (Swift 5.2)

  • 11.x (Swift 5.1)

  • 10.x (Swift 5.0)

  • other: (Please fill in the version you are using.)

  • objective c

Originally created by @vgritsenko on GitHub (Jun 16, 2020). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/604 ### Description: There is a memory leak in OAuthSwift. Observer which is registered with notification center in `observeCallback(_:)` is saved to `self.observer` property, and when this observer is removed later in `removeCallbackNotificationObserver()`, the `self.observer` is never cleared out, keeping observation block in memory, thus keeping the `block` passed in as an argument to `observeCallback` in memory, and everything that block refers to. ``` diff --git a/Pods/OAuthSwift/Sources/OAuthSwift.swift b/Pods/OAuthSwift/Sources/OAuthSwift.swift index 07ea49851..902f0e550 100644 --- a/Pods/OAuthSwift/Sources/OAuthSwift.swift +++ b/Pods/OAuthSwift/Sources/OAuthSwift.swift @@ -67,6 +67,7 @@ open class OAuthSwift: NSObject, OAuthSwiftRequestHandle { public func removeCallbackNotificationObserver() { if let observer = self.observer { OAuthSwift.notificationCenter.removeObserver(observer) + self.observer = nil } } ``` ### OAuth Provider? (Twitter, Github, ..): Facebook, Google, any other. ### OAuth Version: - [X] Version 1 - [X] Version 2 ### OS (Please fill the version) : - [X] iOS : All versions - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [ ] Carthage - [X] CocoaPods - [ ] Swift Package Manager - [ ] Manually ### Library version: - [X] head - [X] v2.1.0 - [X] v2.0.0 - [X] v1.4.1 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [X] 11.4 (Swift 5.2) - [X] 11.x (Swift 5.1) - [X] 10.x (Swift 5.0) - [ ] other: (Please fill in the version you are using.) - [ ] objective c
kerem closed this issue 2026-03-03 16:48:19 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#392
No description provided.