Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
chore: fix memory leak (#1761)
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Umer authored and saeedbashir committed Jun 15, 2023
1 parent 688a980 commit 2a81af1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions Source/AuthenticatedWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,15 @@ public class AuthenticatedWebViewController: UIViewController, WKUIDelegate, WKN
return requestURL.contains(type.rawValue)
}

public func removeCallbackHandler() {
configurations.userContentController.removeAllUserScripts()
if #available(iOS 14.0, *) {
configurations.userContentController.removeAllScriptMessageHandlers()
} else {
configurations.userContentController.removeScriptMessageHandler(forName: AJAXCallBackHandler)
}
}

public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
if message.name == AJAXCallBackHandler {
guard let data = message.body as? Dictionary<AnyHashable, Any> else { return }
Expand Down
7 changes: 3 additions & 4 deletions Source/CourseDatesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class CourseDatesViewController: UIViewController, InterfaceOrientationOverridin

private let datesLoader = BackedStream<(CourseDateModel, UserPreference?)>()
private let courseDateBannerLoader = BackedStream<(CourseDateBannerModel)>()
private var stream: OEXStream<(CourseDateModel, UserPreference?)>?

private lazy var tableView: UITableView = {
let tableView = UITableView()
Expand Down Expand Up @@ -177,10 +176,10 @@ class CourseDatesViewController: UIViewController, InterfaceOrientationOverridin
let preferenceStream = environment.dataManager.userPreferenceManager.feed.output
let networkRequest = CourseDatesAPI.courseDatesRequest(courseID: courseID)
let datesStream = environment.networkManager.streamForRequest(networkRequest)
stream = joinStreams(datesStream, preferenceStream)
datesLoader.addBackingStream(datesLoader)
let stream = joinStreams(datesStream, preferenceStream)
datesLoader.addBackingStream(stream)

stream?.listen(self) { [weak self] response in
stream.listen(self) { [weak self] response in
self?.refreshController.endRefreshing()
switch response {
case .success((var courseDateModel, let userPreference)):
Expand Down
1 change: 1 addition & 0 deletions Source/HTMLBlockViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ class HTMLBlockViewController: UIViewController, CourseBlockViewController, Prel
}

deinit {
webController.removeCallbackHandler()
NotificationCenter.default.removeObserver(self)
}
}
Expand Down

0 comments on commit 2a81af1

Please sign in to comment.