GithubHelp home page GithubHelp logo

Comments (3)

andersio avatar andersio commented on April 28, 2024

If you obtain a reference to the produced signal, it does turn nil after completion.

This is caused by a caveat of Swift's ref-counting implementation: while the object is deinitialized after its last strong reference is ceased, the object would not be freed until all its weak references have been touched.

If you do not retain the cancel disposable, which indirectly holds a weak reference to the signal, Instruments would no longer catch this leak.

https://github.com/apple/swift/blob/master/docs/weak.rst#implementation
(Despite not being updated post-1.0, Swift's ref counting still works this way)

However, it does have a very important downside: since the system cannot clear all the references, it is impossible to actually deallocate an object that is still weakly-referenced (although it can be finalized). Instead, the system must wait for all the weak references to at least be accessed. We call this "husk leaking".

from reactiveswift.

emuye avatar emuye commented on April 28, 2024

@andersio Thanks for responding so quicky. Can you show me the code for seeing the reference go to nil after completion?

from reactiveswift.

andersio avatar andersio commented on April 28, 2024

Instruments caught a leak. But the signal is freed after accessing the weak signal property (which gives you a nil), or when self deinitializes.

    weak var signal: Signal<(), NoError>?
    @IBAction func buttonTouchedUpInside(_ sender: Any) {
       SignalProducer<(), NoError>.empty.startWithSignal { signal, _ 
           self.signal = signal
       }
    }

No leak was caught.

    @IBAction func buttonTouchedUpInside(_ sender: Any) {
       SignalProducer<(), NoError>.empty.startWithCompleted {}
    }

Instruments caught a leak, but the signal should be freed after the disposable is thrown away.

    var disposable: Disposable?
    @IBAction func buttonTouchedUpInside(_ sender: Any) {
       disposable = SignalProducer<(), NoError>.empty.startWithCompleted {}
    }

from reactiveswift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.