How to speed up Children.Clear() in grid layout?

Asides from creating a new instance of a grid, is there anyway to speed up how a grid clears & populates it's children?

When there aren't too many Children, they perform pretty good. However, when a certain threshold is reached, it can take a few seconds to perform, and can even cause an OOM crash.

Clearing and populating grids is a core part of the layout process throughout the app (which at this stage is quite big). Unfortunately, I learned too late into the project that this was a problem, and therefore a fix/workaround would be much easier than implementing other methods.

If anyone has any ideas/solutions, I would be very grateful.

Thanks very much,

Best Answer

  • PhilMcVeighPhilMcVeigh NZ ✭✭
    Accepted Answer

    @karanthakkar
    Thanks for that. After playing around a bit, I discovered that removing the grid from it's parent then clearing column and row definitions speeds it up hugely.

    Still have my oom problem though, which might therefore be unrelated

Answers

  • karanthakkarkaranthakkar USMember ✭✭
    edited November 2017

    i also face this issue on my earlier days with xamarin,
    what i found is grid is always painful while displaying data probably large amount of data.
    i saw your concern but still i suggest you to use FlowListView
    https://github.com/daniel-luberda/DLToolkit.Forms.Controls/tree/master/FlowListView

    it can fulfill your needs.

  • PhilMcVeighPhilMcVeigh NZMember ✭✭
    Accepted Answer

    @karanthakkar
    Thanks for that. After playing around a bit, I discovered that removing the grid from it's parent then clearing column and row definitions speeds it up hugely.

    Still have my oom problem though, which might therefore be unrelated

  • aw2aw2 USMember ✭✭

    Children.Clear() took 2500ms

    Children.ToList().Clear() took 18ms

  • aw2aw2 USMember ✭✭

    @aw2 said:
    Children.Clear() took 2500ms

    Children.ToList().Clear() took 18ms

    don't listen to this mad man

  • ana_xamana_xam Member

    If you have many controls in Grid do not use Children.Clear(), create a new instance of Grid instead.

Sign In or Register to comment.