Questions tagged [deinit]

Swift programming language object destructor

A deinitializer is called immediately before a class instance is deallocated. You write deinitializers with the deinit keyword, similar to how initializers are written with the init keyword. Deinitializers are only available on class types.

102 questions
0
votes
1 answer

Cannot Form Weak Reference To Instance Of Class - Swift Error

I am getting the error: objc[12772]: Cannot form weak reference to instance (0x137d65240) of class appName.ViewController. It is possible that this object was over-released, or is in the process of deallocation. I find this strange because this…
swiftnooby
  • 11
  • 2
0
votes
2 answers

deinit is not being called. Help me fix this

class MyClass { func greeting() { answer += "Hello, World!" } } class Handler { var closure: (() -> Void)? let obj = MyClass() func setupClosure() { closure = { self.obj.greeting() } …
David S
  • 55
  • 7
0
votes
1 answer

ViewController passed as parameter is not being deinitialized (Swift)

Setup: I have a ViewController ProblemView and class A. I pass ProblemView to class A, so I can work on it. It looks like this (simplified): class ProblemView: UIViewController{ var instanceOfA = A() instanceOfA.passView(passedVC:…
0
votes
1 answer

Deinitialization order is different when creating array differently

TL;DR: Why, when the array is created together with initial values, the values are de-initialized right away, but filling the array values after the array is created produces different behavior? I'm learning Swift after JavaScript, which has GC, so…
Parzh from Ukraine
  • 7,999
  • 3
  • 34
  • 65
0
votes
1 answer

UIViewController initialized via UIStoryboard.instantiateViewController does not deinit during unit test when set to nil

I can't figure out why a UIViewController instantiated with UIStoryboard.instantiateViewController does not deinit when initalized in a unit test Here's the code that I expect to deinit but does not: func testDoesNotDeinit() throws { var…
wyu
  • 1,793
  • 17
  • 33
0
votes
1 answer

Save data to database before viewcontroller deallocated

I have a viewcontroller showing the detail of a book. What I want to do is saving data to database in a background thread before the viewcontroller is poped from the navigationcontroller. I don't know where to put the logic save data to database,…
Nhu Nguyen
  • 187
  • 1
  • 3
  • 15
0
votes
1 answer

RxSwift | Initialize and push UIViewController in closure

For example we have three UIViewControllers: A, B, C. We pushing B from A. In B we calling some API: func getProduct(productNumber: String) { someService.rxGetProduct(productNumber: productNumber) .asObservable() …
0
votes
2 answers

View Controllers deinitialized still memory leak

I have deinit method in all my VCs to check if they are being deinitialized or not deinit { print("\(self.description) successfully deinitialized") } When I logout, I see all my view controllers are deinitialized and my…
mutAnT
  • 464
  • 3
  • 17
0
votes
1 answer

Deinit UIViewController after adding it as a subview

I need to add a viewcontroller as a subview of mt current view, but cannot deinit after I don't need it anymore let viewController = CountrySelectViewController() viewController.view.frame = self.view.bounds …
user1620350
0
votes
1 answer

Swift closure is still in memory after VC deinit is called

I have a bluetooth class which passes when a char value is updated to a closure in a view controller (as well as the same closure in a singleton class). when the VC deinit is called, the closure in the VC is still being executed when the char value…
Phil
  • 151
  • 9
0
votes
0 answers

Swift - Deinitialize Views using conditional unwind/perform Segue with

I am using a UINavigationController within my application. And I am trying my best to manage memory allocation. All my views do have a deinit method which are called/printed whenever an unWindSegue or navigationController.popViewController() is…
0
votes
1 answer

Will deinit gets called when a view controller gets disappeared?

I created two view controllers like Navigation controller -> View Controller -> Details View Controller 1 2 3 The (2) View Controller has a button in it which when clicked will shows (3) Details…
John Doe
  • 2,225
  • 6
  • 16
  • 44
0
votes
1 answer

Deinitialize presented view controller

I have the next function func switchRootViewController(rootViewController: UIViewController) { let window = UIApplication.shared.windows.first! window.rootViewController = rootViewController window.makeKeyAndVisible() } And I use it in…
0
votes
1 answer

Swift iOS -View Controller deinit runs when adding it to a new keyWindow

I have a view controller (OrangeVC) that I add to a class that contains a new keyWindow(NewKeyWindowClass). A button in a different vc is tapped and it triggers this new window to get shown over the app's main window and it animates from the right…
Lance Samaria
  • 17,576
  • 18
  • 108
  • 256
0
votes
1 answer

View controller retaining another when changing rootViewController

I've found a memory leak in an app where the following is done: Imagine two view controllers, each of which calls a function in the appDelegate similar to this: func switchRootViewController() { let vc = getTheOtherViewController() …
Alexandre G
  • 1,655
  • 20
  • 30