MemoryLeakTracker is a library that helps track memory leaks.
Leak notification methods:
- Local push notifications
- Alert
- Message on console
MemoryLeakTracker is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'MemoryLeakTracker'
In the AppDelegate file you need to add
import MemoryLeakTracker
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let configs = MLTConfiguration(
isEnable: true,
notificationType: [.push, .console, .alert],
messageTrigger: 2
)
MemoryLeakTracker.shared.configure(configs)
setupPushNotifications(on: application)
setRootViewController()
return true
}
In the observed screens, example
import MemoryLeakTracker
class BaseViewController: UIViewController {
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
MemoryLeakTracker.shared.append("\(self)")
}
required init?(coder: NSCoder) {
super.init(coder: coder)
MemoryLeakTracker.shared.append("\(self)")
}
deinit {
MemoryLeakTracker.shared.remove("\(self)")
}
}
struct MLKConfiguration {
/// Is the library included
let isEnable: Bool
/// Ignored classes
let ignoreClasses: [String]
/// Method of notification:
/// .push - local push(you need to set up push notifications in your application!)
/// .alert - present alert on top screen
/// .console - print on console
/// .none - not notify
let notificationType: [NotificationType]
/// The required number of matches for the assumption of leakage
let messageTrigger: Int
/// Logging of all library activities in the console
let logOnConsole: Bool
}
You can call a ViewController displaying all the logs
let logsViewController = MemoryLeakTrackerController.load()
present(logsViewController, animated: true)