fastred / deallocationchecker Goto Github PK
View Code? Open in Web Editor NEWCatch leaking view controllers without opening Instruments.
Home Page: http://holko.pl/2017/06/26/checking-uiviewcontroller-deallocation/
License: MIT License
Catch leaking view controllers without opening Instruments.
Home Page: http://holko.pl/2017/06/26/checking-uiviewcontroller-deallocation/
License: MIT License
You can't use the word "type" for a let/var because there is a function called "type"
let type = type(of:self)
Some time ago (between Xcode 8.3.x and Xcode 9.4) integration through Carthage stopped working. Quick analysis shows that:
#if DEBUG
scope isn't entered#if DEBUG / #endif
condition (which is there just for optimization reasons), the assertion still wouldn't fail when neededI haven't found any justification for this but it seems that at some point Swift Flags and/or Active Compilation Conditions set in the app project stopped being propagated to precompiled frameworks. This looks like a bug fix on Apple's side.
CocoaPods integration is still operational.
Getting this warning when building with the latest version of Xcode.
The use of Swift 3 @objc inference in Swift 4 mode is deprecated. Please address deprecated @objc inference warnings, test your code with “Use of deprecated Swift 3 @objc inference” logging enabled, and then disable inference by changing the "Swift 3 @objc Inference" build setting to "Default" for the "DeallocationChecker" target.
DeallocationChecker is reporting a leak for me when the view controller I've assigned as searchResultsController
in a UISearchController
is dismissed. If I understand everything correctly, I don't think this should count as a leak, similar to how UITabBarController
is handled, although I'm not 100% sure.
I like it, but don't really want to litter all of my VC's with this method everywhere.
Wouldn't Instruments Leak profiling do the same thing though?
Hello,
I think your project is very interesting and I just want to give it a try. Unfortunately I get it in the SWP not imported. I always get the following error message:
The package dependency graph can not be resolved; unable find any available tag for the following requirements:
https://github.com/fastred/DeallocationChecker/ — 2.0.1..<3.0.0
Hi, just my 2 cents, because I don‘t want to manually add viewWillDisappear(_:) to all of my view controllers I swizzled the UIViewController method for the check:
import UIKit
private func swizzle(forClass: AnyClass, originalSelector: Selector, swizzledSelector: Selector) {
let originalMethod = class_getInstanceMethod(forClass, originalSelector)
let swizzledMethod = class_getInstanceMethod(forClass, swizzledSelector)
method_exchangeImplementations(originalMethod, swizzledMethod)
}
extension UIViewController {
class func swizzleForDeallocationCheck() {
#if DEBUG
swizzle(forClass: self, originalSelector: #selector(viewWillDisappear(_:)), swizzledSelector: #selector(swizzledViewWillDisappear(animated:)))
#endif
}
@objc
private func swizzledViewWillDisappear(animated: Bool) {
#if DEBUG
self.swizzledViewWillDisappear(animated: animated)
//print("viewWillDisappear: class \(type(of: self))")
let delay: TimeInterval = 2.0
// We don't check `isBeingDismissed` simply on this view controller because it's common
// to wrap a view controller in another view controller (e.g. a stock UINavigationController)
// and present the wrapping view controller instead.
if isMovingFromParentViewController || rootParentViewController.isBeingDismissed {
let type = type(of: self)
let disappearanceSource: String = isMovingFromParentViewController ? "removed from its parent" : "dismissed"
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: { [weak self] in
assert(self == nil, "\(type) not deallocated after being \(disappearanceSource)")
})
}
#endif
}
private var rootParentViewController: UIViewController {
var root = self
while let parent = root.parent {
root = parent
}
return root
}
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
UIViewController.swizzleForDeallocationCheck()
// ...
}
Ideas:
Got this error with the latest version:
Pods/DeallocationChecker/Sources/DeallocationChecker.swift:45:17: Method 'objc_dch_checkDeallocation(delay:)' with Objective-C selector 'dch_checkDeallocationAfterDelay:' conflicts with method 'dch_checkDeallocation(afterDelay:)' with the same Objective-C selector
I'm at swift 3.2, Xcode 9.0.1
Does checking for deallocation in viewDidDissapear() of a ViewController hold by a UITabBarController make sense?
If UIKit handles when to deinit VC's on a UITabBarcontroller, could be the case that asserting if self is nil after disappearing not always is right?
Trying to use this in an objC project, but it never fires an error even if I'm 100% sure the VC is not being deallocated...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.