Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Memory consumption of virtual TableViewers
Memory consumption of virtual TableViewers [message #333721] Mon, 29 December 2008 10:42 Go to next message
David  Pérez is currently offline David PérezFriend
Messages: 228
Registered: July 2009
Senior Member
Hi all,

I have in my app a virtual TableViewer (SWT.VIRTUAL) that shows a lot of
items.
My custom ILazyContentProvider doesn't maintain all the items, it fetches
on the fly from a database as needed.

Theorically the memory consumption of my app would be very low,
independent from the number of rows.

But empirically, the memory consumption increases a lot as the number of
rows increases. I have investigated a little with the MAT tool
(http://www.eclipse.org/mat/), and I get that the TableViewer component is
holding for a TableViewer with 15403 rows this numbers:

15403 org.eclipse.swt.widgets.TableItem's which holds 6 Mb of memory
23006 int[]'s
40325 String's with over 2 Mb memory
....

I need to display over 1,000,000 rows, so TableViewer's aren't scalable.

Is it possible to optimize the memory somehow?
Thanks in advance for any valuable tip.
Re: Memory consumption of virtual TableViewers [message #333722 is a reply to message #333721] Mon, 29 December 2008 10:51 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi David,

Short answer - no. Virtual only means that the items are not created at
once but only when they are scrolled into view but they won't get
collected once they are scrolled out of view.

Maybe something like a paging table could solve this issue.

Tom

David Pérez schrieb:
> Hi all,
>
> I have in my app a virtual TableViewer (SWT.VIRTUAL) that shows a lot of
> items.
> My custom ILazyContentProvider doesn't maintain all the items, it
> fetches on the fly from a database as needed.
>
> Theorically the memory consumption of my app would be very low,
> independent from the number of rows.
>
> But empirically, the memory consumption increases a lot as the number of
> rows increases. I have investigated a little with the MAT tool
> (http://www.eclipse.org/mat/), and I get that the TableViewer component
> is holding for a TableViewer with 15403 rows this numbers:
>
> 15403 org.eclipse.swt.widgets.TableItem's which holds 6 Mb of memory
> 23006 int[]'s
> 40325 String's with over 2 Mb memory
> ...
>
> I need to display over 1,000,000 rows, so TableViewer's aren't scalable.
>
> Is it possible to optimize the memory somehow?
> Thanks in advance for any valuable tip.
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Memory consumption of virtual TableViewers [message #333723 is a reply to message #333721] Mon, 29 December 2008 10:58 Go to previous messageGo to next message
David  Pérez is currently offline David PérezFriend
Messages: 228
Registered: July 2009
Senior Member
Further investigation:

public class Table {
TableItem [] items; // <--- This is the guilty of memory excesive use

....

// This is where the items are created and never released....
TableItem _getItem (int index) {
if ((style & SWT.VIRTUAL) == 0) return items [index];
if (items [index] != null) return items [index];
return items [index] = new TableItem (this, SWT.NONE, -1, false);
}
}

Maybe this is a topic for the SWT newsgroup.
I'll post there.

David Pérez wrote:

> Hi all,

> I have in my app a virtual TableViewer (SWT.VIRTUAL) that shows a lot of
> items.
> My custom ILazyContentProvider doesn't maintain all the items, it fetches
> on the fly from a database as needed.

> Theorically the memory consumption of my app would be very low,
> independent from the number of rows.

> But empirically, the memory consumption increases a lot as the number of
> rows increases. I have investigated a little with the MAT tool
> (http://www.eclipse.org/mat/), and I get that the TableViewer component is
> holding for a TableViewer with 15403 rows this numbers:

> 15403 org.eclipse.swt.widgets.TableItem's which holds 6 Mb of memory
> 23006 int[]'s
> 40325 String's with over 2 Mb memory
> ....

> I need to display over 1,000,000 rows, so TableViewer's aren't scalable.
Re: Memory consumption of virtual TableViewers [message #333724 is a reply to message #333722] Mon, 29 December 2008 11:01 Go to previous messageGo to next message
David  Pérez is currently offline David PérezFriend
Messages: 228
Registered: July 2009
Senior Member
Thanks Tom for your quick answer. :-)

Do you consider is it easy to implement such a paging table?
Does anybody know a Table replacement?

Tom Schindl wrote:

> Hi David,

> Short answer - no. Virtual only means that the items are not created at
> once but only when they are scrolled into view but they won't get
> collected once they are scrolled out of view.

> Maybe something like a paging table could solve this issue.

> Tom
Re: Memory consumption of virtual TableViewers [message #333725 is a reply to message #333722] Mon, 29 December 2008 11:07 Go to previous messageGo to next message
David  Pérez is currently offline David PérezFriend
Messages: 228
Registered: July 2009
Senior Member
Hi,

I'm going to study this a little more and let you know of any advances.

If I manage to solve this problem, my intention is to share my code with
this newsgroup.

David

Tom Schindl wrote:

> Hi David,

> Short answer - no. Virtual only means that the items are not created at
> once but only when they are scrolled into view but they won't get
> collected once they are scrolled out of view.

> Maybe something like a paging table could solve this issue.

> Tom
Re: Memory consumption of virtual TableViewers [message #333730 is a reply to message #333724] Tue, 30 December 2008 09:09 Go to previous message
David  Pérez is currently offline David PérezFriend
Messages: 228
Registered: July 2009
Senior Member
Here is my solution that works:

public class PagedTable extends Table {
int[] selectedIndices;

public PagedTable(Composite parent, int style) {
super(parent, style | SWT.VIRTUAL);
}

private void freeUnusedItems(Widget ignoreItem) {
if (items.length > 0) {
int[] range = getVisibleRange();
selectedIndices = getSelectionIndices();
for (int i = 0; i < range[0]; i++) {
releaseItem(i, ignoreItem);
}
for (int i = range[1]+1; i < items.length; i++) {
releaseItem(i, ignoreItem);
}
}
}

private void releaseItem(int i, Widget ignoreItem) {
if (items[i] != null && items[i] != ignoreItem) {
for (int j = 0; j < selectedIndices.length; j++) {
// No liberar elementos seleccionados
if (selectedIndices[j] == i) {
return;
}
}
if (!items[i].isDisposed()) {
items[i].release(false);
}
items[i] = null;
}
}

public int[] getVisibleRange() {
int[] res = new int[2];
int height = getItemHeight();
int totalHeight = getSize().y;
if (getHeaderVisible()) {
totalHeight -= getHeaderHeight();
}
res[0] = getTopIndex();
res[1] = res[0]+(totalHeight+height-1)/height-1;
return res;
}

@Override TableItem _getItem(int index) {
TableItem res = super._getItem(index);
freeUnusedItems(res);
return res;
}

@Override void postEvent(int eventType, Event event) {
super.postEvent(eventType, event);
if (eventType == SWT.SELECTED) {
freeUnusedItems(event.item);
}
}
}

This class must be placed in the existing org.eclipse.swt plugin, as
Eclipse doesn't ease the expandibility of builtin classes in any other way.

I hope this will be useful to someone else.

David Pérez wrote:

> Thanks Tom for your quick answer. :-)

> Do you consider is it easy to implement such a paging table?
> Does anybody know a Table replacement?

> Tom Schindl wrote:

>> Hi David,

>> Short answer - no. Virtual only means that the items are not created at
>> once but only when they are scrolled into view but they won't get
>> collected once they are scrolled out of view.

>> Maybe something like a paging table could solve this issue.

>> Tom
Previous Topic:Resource Change Listener via XML?
Next Topic:Perform project updates during/post plugin update
Goto Forum:
  


Current Time: Thu Apr 25 10:21:26 GMT 2024

Powered by FUDForum. Page generated in 0.03711 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top