MutableCopy of CNMutableContact memory leak when try to update more than 300 contacts at once using loop

Viewed 55

I am stuck on an issues to update more than 300 contacts at once. When I try to update the mutablecontact image which is real contact as mutablablecopy, A memory leak occurs.

RAM usage corsses 1.4GB and then the application crahses. This my code.

if let mutableCopy = contact.mutableCopy() as? CNMutableContact {
                                                                
    ImageDownloader.default.downloadImage(with: URL(string: thumbnailImageURL)!) { result in
                                    
      switch result {
         case .success(let value):
              queue.sync {
                     SVProgressHUD.show(withStatus: "loading 1")
                     //mutableCopy.imageData = compressedImage?.pngData()
                     mutableCopy.imageData = value.image.pngData() //self.returnCustomSizeImage(image: value.image).pngData()
                     mutableCopy.givenName  = givenName
                     mutableCopy.phoneNumbers = [CNLabeledValue(label: self.responsedContactsArray[index2].label ?? "NO DOB", value: CNPhoneNumber(stringValue: "\(trimmedPhoneNumber)"))]
                                            
                    //mutableCopy.familyName = "‍"
                    saveRequest.update(mutableCopy)
                                            
                      do {
                           try AppDelegate.mContactStore.execute(saveRequest)
                          } catch let error {
                                 SVProgressHUD.dismiss()
           }
         }
0 Answers
Related