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

Memory leak when casting Array of AnyObjects ([AnyObject]) to [AnyHashable]

    XMLWordPrintable

    Details

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

      Description

      https://pastebin.com/xaQ94TWb

      The cast succeeds but deinit is never called and our objects are never deallocated. This also happens if I compactMap through the array and try to add each one individually.

      import UIKit
      
      
      class Test: Hashable {
       static func == (lhs: Test, rhs: Test) -> Bool {
       return lhs.str == rhs.str
       }
       
       deinit {
       print("hello!")
       }
       
       func hash(into hasher: inout Hasher) {
       hasher.combine(str)
       }
       
       var str: String = "test"
      }
      
      class ViewController: UIViewController {
      
      override func viewDidLoad() {
       super.viewDidLoad()
       var t = Test()
       var t2 = Test()
       var values: [AnyObject] = [t,t2]
       
       let hashable: [AnyHashable] = values as! [AnyHashable]
       
       // Do any additional setup after loading the view, typically from a nib.
       }
      
      
      }
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            carboncomputed Kevin Carbone
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: