Code Monkey home page Code Monkey logo

Comments (4)

tele-bird avatar tele-bird commented on July 20, 2024

I have the same issue, and am looking at ReverseInit(), which is supposed to be invoked when the page is popped from the navigation stack. However, I'm not seeing it get invoked when I pop the page using CoreMethods.PopPageModel(). I suspect that ReverseInit() is invoked not on the pagemodel that was popped, but on the pagemodel that pushed it. So, in that case, it isn't appropriate for disposing subscriptions.

I see that Prism's BaseViewModel implements IDestructible - see the bottom of this page: https://prismlibrary.com/docs/xamarin-forms/creating-your-first-prism-app.html#anatomy-of-a-prism-application

@yevgeny-sotnikov did you find out another way using FreshMVVM ?s

@rid00z Is there something like this? Would be great to have this as it's a very common use case.

from freshmvvm.

yevgeny-sotnikov avatar yevgeny-sotnikov commented on July 20, 2024

I have the same issue, and am looking at ReverseInit(), which is supposed to be invoked when the page is popped from the navigation stack. However, I'm not seeing it get invoked when I pop the page using CoreMethods.PopPageModel(). I suspect that ReverseInit() is invoked not on the pagemodel that was popped, but on the pagemodel that pushed it.

ReverseInit() needed to pass some result back to view-model, so it isn't applicable for our use-case.

@tele-bird unfortunatelly i still have this issue, no any proper ways to understand that page is destroying

from freshmvvm.

tele-bird avatar tele-bird commented on July 20, 2024

Maybe the PageWasPopped event could suffice? Though it says that it might not be raised every time a page is popped, so probably not suitable to completely avoid memory leaks unless it is improved.

https://github.com/rid00z/FreshMvvm/blob/3ccf13b0b506b6e7193cdadde1d988ac76ac6889/src/FreshMvvm/FreshBasePageModel.cs

cc: @yevgeny-sotnikov , @rid00z

from freshmvvm.

tele-bird avatar tele-bird commented on July 20, 2024

@yevgeny-sotnikov
I recently discovered the FreshBasePageModel.PageWasPopped event, and I think it can be used for the important memory-conserving best-practices that you need. It is better than using ViewIsAppearing/ViewIsDisappearing because it only fires when you don't need it any more. Along with unsubscribing from events, I plan to use it to implement Disposable pattern, for IDisposable objects referenced by my pages. Hope this helps!

In my implementation, my base class unsubscribes from further notifications after the first one (line 10), since the page is quite unlikely to be popped a 2nd time!

    public class BasePageModel : FreshBasePageModel
    {
        public BasePageModel(IConnectivity connectivityService)
        {
            PageWasPopped += HandlePageWasPopped;
        }

        private void HandlePageWasPopped(object sender, EventArgs e)
        {
            PageWasPopped -= HandlePageWasPopped;
            OnPagePopped(sender, e);
        }

        protected virtual void OnPagePopped(object sender, EventArgs e)
        {
        }
    }

from freshmvvm.

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.