Uploaded image for project: 'Swift'
  1. Swift
  2. SR-9282

Weak variables in structs leak on String(describing:) or print

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Duplicate
    • Component/s: None
    • Labels:

      Description

      The following code should print "Deinit!" before exiting.  It does print this on the Swift 4.1 Snapshot 2018-05-31 toolchain, but does not on the Swift 4.2 toolchain that ships with Xcode 10.

      class DeinitDetector {
      	deinit {
      		print("Deinit!")
      	}
      }
      struct WeakHolder {
      	weak var a: DeinitDetector!
      }
      do {
      	let a = DeinitDetector()
      	let b = WeakHolder(a: a)
      	let _ = String(describing: b)
      }
      

       More info here https://forums.swift.org/t/struct-with-weak-ref-memory-issue/18040

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              TellowKrinkle TellowKrinkle
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: