Giter VIP home page Giter VIP logo

Comments (4)

glennawatson avatar glennawatson commented on April 27, 2024

Do you need to dispose is the first reaction. Observables often do not.

from reactiveui.

JakenVeina avatar JakenVeina commented on April 27, 2024

Strictly speaking, probably not. .Deactivate(ignoreRefCount: true) should force the removal of the sensitive references that could cause a memory leak if left alive.

This still seems like a violation of the class's apparent contract. And to me, there's value in Disposing the activator, in that if something DOES try to activate it again, I get an exception, and a bug in my own code is revealed.

from reactiveui.

glennawatson avatar glennawatson commented on April 27, 2024

Observables aren't honoring that contract anyway. They just adopted the IDisposable to get advantages of some of the mechanics. It's a mistake to think you have to dispose all of them. Depends on ownership of the handle.

from reactiveui.

JakenVeina avatar JakenVeina commented on April 27, 2024

I meant more the "contract" regarding the Activated and Deactivated events. That's got nothing to do with disposal mechanics.

Actually, scratch what I said earlier. ViewModelActivator.Deactivate(ignoreRefCount: true) does not clear out all potentially sensitive references, because the two subjects for Activated and Deactivated could have subscribers, and the only way to clear those, currently, is through disposal.

I think an appropriate change would be from...

public void Deactivate(bool ignoreRefCount = false)
{
    if (Interlocked.Decrement(ref _refCount) == 0 || ignoreRefCount)
    {
        Interlocked.Exchange(ref _activationHandle, Disposable.Empty).Dispose();
        _deactivated.OnNext(Unit.Default);
    }
}

...to...

public void Deactivate(bool ignoreRefCount = false)
{
    var wasActive = ignoreRefCount
        ? (Interlocked.Exchange(ref _refCount, 0) != 0)
        : (Interlocked.Decrement(ref _refCount) == 0);

    if(wasActive)
    {
        Interlocked.Exchange(ref _activationHandle, Disposable.Empty).Dispose();
        _deactivated.OnNext(Unit.Default);
    }
}

from reactiveui.

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.