Memory leak declaring constants

Working with tools the other day I ran with a memory leak into a very simple code example as follows:

@IBAction func shareSheet(sender: AnyObject) {

    let firstActivityItem = "Hello there is a memory leak here..."

    let secondActivityItem : NSURL = NSURL(string: "http://www.sample.com/")!

    let activityViewController : UIActivityViewController = UIActivityViewController(
        activityItems: [firstActivityItem, secondActivityItem], applicationActivities: nil)

    activityViewController.popoverPresentationController?.sourceView = (sender as! UIButton)

    self.presentViewController(activityViewController, animated: true, completion: nil)
} 

The purpose of the above code is to show a UIActivityViewControllermessage on a social network, etc.

Tools leak screenshots :

enter image description here


enter image description here

Working on the problem, I finally decided to change the declaration of the two constants firstActivityItemand secondActivityItemvariables, a memory leak disappeared.

But my question is: why is this?

Why generate a memory leak with let, rather than with an ad var?

+4
source share
1 answer

Best of all, this is a Swift issue that can be resolved with an upgrade.

, .

: http://bugreport.apple.com

0

All Articles