Created
September 28, 2017 02:15
-
-
Save jkereako/cf7a00c3e0ba71b604a8adb172f18fcf to your computer and use it in GitHub Desktop.
Free `self` in Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class TabBarController: UITabBarController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Copy the reference `self` into a variable. | |
var selfCopy = self | |
// Implicitly cast `selfCopy` to a UnsafeMutableRawPointer. | |
let ptr = UnsafeMutableRawPointer(&selfCopy) | |
// Set it free! | |
free(ptr) | |
// Here's another way... | |
withUnsafeMutablePointer(to: &selfCopy) { ptr in | |
free(ptr) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment