I am developing an application with swift.
Memory leaks when using the UIActivityViewController to display activity dialogs.
I'm in trouble because I don't know how to solve the leak.Please tell me how to solve this problem.
I'll put the code at the end.(Partial rewriting)
The action is to send the output CSV file via AirDrop or mailer as shown in the activity dialog.
I have attached the ss that I checked with the instruments, which I ran on iphone(ios8.4) and ipadmini(ios9.3.4).I went to the screen where each dialog was displayed and opened and closed the dialog 5 times.
↑ On the iphone, NSMutableArray seems to be leaking in _UIAlertControllerCommmonInit.There are two leaks in this ss, but sometimes they leak as many times as they open and close.
↓ For ipad ss, I will put 3 sheets with different stack trace contents.(Only the IsImage and IsContact parts are different like IsPDF.)
On ipad, NSCFSstring is leaking like crazy in "CSStringCopyCFSString".Furthermore, I am concerned about the fact that the heap is high every time it opens and closes (is there anything left even if I close it?).Please let me know if there are any causes or workarounds for this as well.Thank you for your cooperation.
// Button Press Action (CSV File Creation + Transfer)
funtapButton(){
// Output CSV file
letstrFullPath: String=outputCSVFile("sample.csv")
print("csvpath:" + strFullPath)
// (Output Success) Activity Dialog Display
if strFullPath!="{
_ad=MyAd()// Load Ad
let body: String = NSLocalizedString ("MSG_SEND", comment: "body wording")
let file = NSURL (fileURLWithPath:strFullPath)
let handler: (Bool->Void) = { [unknown self] (completed) in
if completed == true {
self._ad?.show(self)
print("CSV transmission complete!")
}
}
dispatchDialog(self, items: [body, file], btn:btnAction, arrow:.Up, handler:handler)
// (Failed Output) Error Message Display
} else{
dispatchErrMsg(self, strMsg:NSLocalizedString("MSG_FILE_ERR", comment: "Error Occurred"))
}
}
/// Display Activity Dialog
class func dispDialog (vc: UIViewController, items: [AnyObject], btn: UIBarButtonItem, arrow: UIPoverArrowDirection=.Unknown, handler: (Bool->Void)!=nil) {
let dialog = UIAactivityViewController (activityItems: items, applicationActivities:nil)
// Activity Type Not Used
let excluded = [
UIActivityTypeCopyToPasteboard,
UIActivityTypeMessage,
]
dialog.excludedActivityTypes=excluded
// Set post-completion actions
if handler!=nil{
dialog.completionWithItemsHandler={(activityType:String?,completed:Bool,returnItems:[AnyObject]?,error:NSError?)in
print("activityType:\(activityType)")
handler(completed)
return
}
}
// For iPad And Universal Device
iflet popCtrl=dialog.popoverPresentationController{
popCtrl.sourceView=vc.view
popCtrl.permittedArrowDirections=arrow
popCtrl.barButtonItem=btn
}
vc.presentViewController(dialog, animated:true, completion:nil)
}
Objective-C reduces leaks by tightening blocks that cause memory leaks in @autoreleasepool
, so
autoreleasepool{
dispatchDialog(self, items: [body, file], btn:btnAction, arrow:.Up, handler:handler)
}
Also, why don't you combine the displayDialog
function with autoreleasepool
?
610 Uncaught (inpromise) Error on Electron: An object could not be cloned
890 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
577 PHP ssh2_scp_send fails to send files as intended
568 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.