Author Topic: NGUI Timeline scrollview memory management  (Read 9231 times)

Tripwire

  • Full Member
  • ***
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 163
    • View Profile
NGUI Timeline scrollview memory management
« on: March 18, 2014, 06:22:45 PM »
Hi,

I'm testing out building a Timeline in my Unity3D project. And I would like to know what you guys think would be the best approach conserning memory management. Let's say we have a ScrollView in which Timeline events are dynamically added to the scrollview. A Timeline item consists of 3 sprites (from the same atlas) and 3 labels. In my Database I have an event table which holds 20 timeline events which need to be shown in the Timeline scrollview.

What would be the best approach in terms of memory management? Would this be pooling? Or destroying and adding new buttons when the scroll amount reaches a certian threshold?

Example the first 10 items are loaded and when the 11th item should be visible the first item is destroyed. When scrolling back the first item get's created and the 11th item destroyed and so on.

Any ideas?

Tripwire

  • Full Member
  • ***
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 163
    • View Profile
Re: NGUI Timeline scrollview memory management
« Reply #1 on: March 20, 2014, 06:11:43 AM »
Anyone has some suggestions?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Timeline scrollview memory management
« Reply #2 on: March 20, 2014, 12:39:51 PM »
Create/destroy is always more expensive than just disabling the game object and re-using it later.

Tripwire

  • Full Member
  • ***
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 163
    • View Profile
Re: NGUI Timeline scrollview memory management
« Reply #3 on: March 20, 2014, 05:48:29 PM »
Create/destroy is always more expensive than just disabling the game object and re-using it later.

I know but what happends when there are 200+ timelineitems in the scrollview? If the scrollview then becomes really slow wouldn't it be best to load the first 50 items, then when the user scrolls to the bottom load the next 50 items and destroy the top 25 or something?

Or maybe create a script too make sure only 50 items can be in the scrollview at all times others will be loaded / destroyed?

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: NGUI Timeline scrollview memory management
« Reply #4 on: March 20, 2014, 10:53:42 PM »
Is there a object pooling system in NGUI that could be used for this kind of situation ?  2DTK has a scrollview component that can hold an insane amount of items.  NGUI really need to support this kind of functionality.  We are 2014, multicore, etc.  But the GUI is like of the 80's - too raw.

Tripwire

  • Full Member
  • ***
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 163
    • View Profile
Re: NGUI Timeline scrollview memory management
« Reply #5 on: March 21, 2014, 05:08:37 AM »
Is there a object pooling system in NGUI that could be used for this kind of situation ?  2DTK has a scrollview component that can hold an insane amount of items.  NGUI really need to support this kind of functionality.  We are 2014, multicore, etc.  But the GUI is like of the 80's - too raw.

I'd like to know that too about the pooling system. If it isn't available what would be the best option to do the Timeline?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Timeline scrollview memory management
« Reply #6 on: March 21, 2014, 01:16:34 PM »
I'll just add an unlimited scroll view example in the next release, that should answer your questions.

Tripwire

  • Full Member
  • ***
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 163
    • View Profile
Re: NGUI Timeline scrollview memory management
« Reply #7 on: March 22, 2014, 05:35:04 PM »
I'll just add an unlimited scroll view example in the next release, that should answer your questions.

Great! I'm looking forward too it!

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: NGUI Timeline scrollview memory management
« Reply #8 on: March 22, 2014, 11:18:32 PM »
Awesome.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Timeline scrollview memory management
« Reply #9 on: March 23, 2014, 02:54:23 AM »
Done. 3.5.5 is now out with the example.

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: NGUI Timeline scrollview memory management
« Reply #10 on: March 23, 2014, 06:18:17 AM »
Great, thanks for the new example.

I had a look at the code for the example and still trying to figure out how to do the following:

1. I have a list of 300 photos that I would like to display using the new infinite scroller.
2. Using the example infinite scroller which has 9 recycling items.
3. How to feed the 300 photos into the infinite scroller?
4. This is quite a common use case and 2DTK has a built-in scroller that does this. 

Can you add this example so we can see how it's done.

Cheers.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Timeline scrollview memory management
« Reply #11 on: March 23, 2014, 04:02:12 PM »
Create all 300 children. The infinite scroll view's logic automatically disables the children that are not visible so they don't cause any overhead.

Alternatively override the virtual function at the end of the script. It gets called whenever an item gets repositioned, letting you change its data if you like.

Tripwire

  • Full Member
  • ***
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 163
    • View Profile
Re: NGUI Timeline scrollview memory management
« Reply #12 on: March 23, 2014, 06:12:15 PM »
Create all 300 children. The infinite scroll view's logic automatically disables the children that are not visible so they don't cause any overhead.

Alternatively override the virtual function at the end of the script. It gets called whenever an item gets repositioned, letting you change its data if you like.

ArenMook you are amazing! Thanks for the infinite scroller example!! Wish I could press the thank you button more :)

wallabie

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 200
    • View Profile
Re: NGUI Timeline scrollview memory management
« Reply #13 on: March 24, 2014, 02:43:36 AM »
Really, it is that easy?

Just add 300 and the component will take care of the rest.
This is Great.

"Alternatively override the virtual function at the end of the script. It gets called whenever an item gets repositioned, letting you change its data if you like."
Be great if you can make a small example to show this use case.

Cheers.

skatola

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 31
    • View Profile
Re: NGUI Timeline scrollview memory management
« Reply #14 on: August 02, 2016, 10:21:32 AM »
Hi ArenMook
i have this problem too, i have a scrollview with a children grid, how can i use this wrap system with my grid?
tried to replace my ui grid with an object with ui wrap script but don't work like before : (
I need to populate my scroll objects in runtime, with ui grid it is easy, i just call gridparent.GetComponent<UIGrid>().Reposition(); after i populate my scrollview, but with the wrap script all my objects are in the same place, tried to call gridparent.GetComponent<UIWrapContent>().WrapContent(); after i populate my scrollviews but nothing happen, my items are all in the same location : (
thank you like always!

EDIT: solved using SortBasedOnScrollMovement();, it do the jobs : )
« Last Edit: August 02, 2016, 12:32:58 PM by skatola »