Never call content page destructor after CocosSharpView.ViewCreated fired.(Cocossharp+Xamarin Forms)

Never call content page destructor (~MainPage()) after CocosSharpView.ViewCreated fired.
(Cocossharp Forms + Xamarin.Forms + Android plat form.)

Of course, it causes a memory leak.

Simple code is like below. (Same as removed comment out inside HandleViewCreated.)

But, after comment out
//grid.Children.Add(gameView, 0, 0);

or
//ViewCreated = HandleViewCreated

makes calling destructor normally. (When GC.Collect() is called.)

Need more process or something to release ContentPage ? (or bug ?)

Poor English.
Thanks.

public class App : Application
{
    public App()
    {
        Set_MainPage();
    }

    public void Set_MainPage()
    {
        MainPage = new FormsWithCocosSharp.MainPage(this);

        GC.Collect();
    }
}



public class MainPage : ContentPage
{
    App ptr = null;
    Grid grid = null;
    GameScene gameScene = null;

    public MainPage (App ap)
    {
        ptr = ap;

        grid = new Grid ();
        this.Content = grid;
        grid.RowDefinitions = new RowDefinitionCollection {
            new RowDefinition{ Height = new GridLength(1, GridUnitType.Star)},
        };

        var gameView = new CocosSharpView()
        {
            ViewCreated = HandleViewCreated
        };
        grid.Children.Add(gameView, 0, 0);
    }

    ~MainPage()
    {
    }

    protected override bool OnBackButtonPressed()
    {
        grid.Children.Clear();
        ptr.Set_MainPage();

        return true;
    }


    void HandleViewCreated (object sender, EventArgs e)
    {
                return;

        //var gameView = sender as CCGameView;

        //if (gameView != null)
        //{
            //gameView.DesignResolution = new CCSizeI (100, 100);
            //gameScene = new GameScene (gameView);
            //gameView.RunWithScene (gameScene);
                //}
        }
}

Answers

Sign In or Register to comment.