Last active
August 29, 2015 14:22
-
-
Save lukaskubanek/4e3f7657864103d79e3a to your computer and use it in GitHub Desktop.
Memory leak in Swift structures (http://stackoverflow.com/questions/30628547/memory-leak-in-swift-structures-how-to-fix-this)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AppDelegate.swift | |
// SwiftStructsMemoryLeak | |
// | |
// Created by Lukas Kubanek on 03/06/15. | |
// Copyright (c) 2015 Lukas Kubanek. All rights reserved. | |
// | |
import Cocoa | |
protocol Item { | |
var value: String { get } | |
} | |
struct FooItem<T>: Item { | |
let value: String | |
let additionalValue: T | |
init(value: String, additionalValue: T) { | |
self.value = value | |
self.additionalValue = additionalValue | |
} | |
} | |
struct ItemWrapper { | |
let item: Item | |
init(item: Item) { | |
self.item = item | |
} | |
} | |
@NSApplicationMain | |
class AppDelegate: NSObject, NSApplicationDelegate { | |
@IBOutlet weak var window: NSWindow! | |
func applicationDidFinishLaunching(aNotification: NSNotification) { | |
let item = FooItem(value: "protocol value", additionalValue: "foo item value") | |
let _ = ItemWrapper(item: item) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment