     @discardableResult
     public func subscribe(_ function: @escaping (ValueType) -> Void) -> SubscriptionReferenceType? {
         defer { subscriptionToken += 1 }
-        defer { function(value) }
+        retainReference = self
+        function(value)
         let reference = ObservablePropertySubscriptionReferenceType(key: String(subscriptionToken),
                                                             stream: self)
         subscriptions.updateValue(function, forKey: reference)

        ObservablePropertySubscriptionReference<ValueType>
    internal var subscriptions = [ObservablePropertySubscriptionReferenceType : (ValueType) -> ()]()
    private var subscriptionToken: Int = 0
    public var value: ValueType {
        didSet {
            subscriptions.forEach { $0.value(value) }


    internal func unsubscribe(reference: ObservablePropertySubscriptionReferenceType) {
        subscriptions.removeValue(forKey: reference)
        if subscriptions.count == 0 {
            retainReference = nil
        }
    }
}
