skywinder / ActionSheetPicker-3.0

Quickly reproduce the dropdown UIPickerView / ActionSheet functionality on iOS.
http://skywinder.github.io/ActionSheetPicker-3.0
BSD 3-Clause "New" or "Revised" License
3.4k stars 740 forks source link

Memory leaks when using ActionSheetDatePicker on a modally presented UIViewController #358

Closed Bhide closed 4 years ago

Bhide commented 7 years ago

`dateSelector = ActionSheetDatePicker.init(title: "", datePickerMode: .date, selectedDate: Date(), doneBlock: { [unowned self](datePicker, date, index) in debugPrint("selected date: ((date as! NSDate).formatDateTime())")

                self.registerInfo["dob"] = AppUtils.stringFromDate(date: (date as! Date), dateFormat: "MM-dd-yyyy") //(date as! Date)

                self.tableView.beginUpdates()

                let userInfoModel = self.userDetailsDataSource[atindexPath.row]

                userInfoModel.disclosureTextObject = date

                self.userDetailsDataSource[atindexPath.row] = userInfoModel

                self.tableView.reloadRows(at: [atindexPath], with: .none)

                self.tableView.endUpdates()

                self.updateProfileBarButtonItem.isEnabled = true

                }, cancel: { [unowned self](datePicker) in

                }, origin: self.view)`

I ran instruments to check the leaks and found 53 leaks when I dismissed my UIViewController without pressing the ActionSheetDatePicker's Cancel or Done. In this case, the presented UIViewController is not deallocated.

adamhongmy commented 7 years ago

I notice in ActionSheetCustomPicker.h file, the delegate is strong. @property(nonatomic, strong) id <ActionSheetCustomPickerDelegate> delegate; So this property was holding a strong reference to the view controller, which prevented it from ever being deallocated. If you are using ActionSheetCustomPicker class, changing the delegate to weak might solve the problem.

MyNameIsWood commented 6 years ago

@adamhongmy Do you mean modify the source code directly?

adamhongmy commented 6 years ago

@MyNameIsWood Yup. diy or wait for the owner to do so. Btw, if only you use ActionSheetCustomPicker class, then it worth a shot to try it by changing @property(nonatomic, strong) id <ActionSheetCustomPickerDelegate> delegate; to @property(nonatomic, weak) id <ActionSheetCustomPickerDelegate> delegate;

MyNameIsWood commented 6 years ago

@adamhongmy I already do so. Will it cause any other bugs?

adamhongmy commented 6 years ago

@MyNameIsWood Not really. Btw are u calling ActionSheetCustomPicker class?

adamhongmy commented 6 years ago

For me it doesn't affect me whether I change it or not because i'm not using it.

skywinder commented 4 years ago

already fixed, thanks for investigation, @adamhongmy 👍