• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OutOfMemory Exception and JTable

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have 2 Object[][] with about 700-1000 values in one or or both. When these arrays are added to the JTable. an OutOfMemory Exception occures on line 18. After increasing the Heap Size and running the app, a warning message pops up indicating RAM is running low and shortly after the OS hangs. Why is this happening?

I'd like to display these values in a table like format, some advice will be appreciated


I assuming this is a Memory Size Problem (Memory leak?)

Thanks


 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're creating a 1000 x 1000 array but only using 4 of the 1000 columns. Were you going to add code to use the rest later? Because a table with 1000 columns isn't really a good candidate for a JTable.
 
Tim Jones
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:You're creating a 1000 x 1000 array but only using 4 of the 1000 columns. Were you going to add code to use the rest later? Because a table with 1000 columns isn't really a good candidate for a JTable.



Yes, the rest of the columns will be populated in later. If JTable is not the best option in this case, what is the alternative?

Thanks
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So that wasn't a mistake? You really do plan to have a square table? Your existing code looks like you plan to have 1000 rows but only 4 (or maybe 7) columns.
 
Tim Jones
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:So that wasn't a mistake? You really do plan to have a square table? Your existing code looks like you plan to have 1000 rows but only 4 (or maybe 7) columns.



Answer to all these questions is a Yes.

just so it is clear, there are 7 columns in total with give or take 1000+ rows (values).

Anyone have any suggestions?

Thanks
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a table with 1000 rows in is a pretty bad UI (in my opnion). I would stick a filter on it, so the user can actually see data that is relevant to them.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1000 rows is nothing for several applications, including but not limited to database editing / browsing applications.
 
Tim Jones
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:1000 rows is nothing for several applications, including but not limited to database editing / browsing applications.



And your point is?

 
Tim Jones
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Wendy Gibbons wrote:a table with 1000 rows in is a pretty bad UI (in my opnion). I would stick a filter on it, so the user can actually see data that is relevant to them.



Not sure how that will be possible inside a JTable (DefaultTableModel will only take Object[][)]?
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Jones wrote:

Rob Spoor wrote:1000 rows is nothing for several applications, including but not limited to database editing / browsing applications.



And your point is?


It was a response to Wendy's opinion that 1000 rows is too many, nothing else.

Tim Jones wrote:

Wendy Gibbons wrote:a table with 1000 rows in is a pretty bad UI (in my opnion). I would stick a filter on it, so the user can actually see data that is relevant to them.



Not sure how that will be possible inside a JTable (DefaultTableModel will only take Object[][)]?


Perhaps you can create your own AbstractTableModel subclass that does not copy data, but instead uses the original data source with its getRowCount, getValueAt and setValueAt methods.
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:
Perhaps you can create your own AbstractTableModel subclass that does not copy data, but instead uses the original data source with its getRowCount, getValueAt and setValueAt methods.


I second to that. I have a table model capable of displaying millions of cells (if some unfortunate user opens the form in that way), because I don't have a physical object for every cell in the table.

I managed to create a table with around 100.000 columns and 10.000 rows just for testing. It works well, only the horizontal scrolling gets a bit slower when scrolling too far to the right - JTable apparently does not cache horizontal position of the columns and it takes some time to compute them while drawing individual cells. (Or maybe I did it to me myself - I've a customized header renderer in there.)

Note: not that the users usually use these insanely large tables. But whichever limit we impose, they always want a few rows more. The user interface allows them to export the contents of the table to MS Excel, which can accommodate million rows and thousand columns nowadays....
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Jones wrote:just so it is clear, there are 7 columns in total with give or take 1000+ rows (values).



Thanks for the clarification. So my suggestion would be to change your array declaration

so that it only has 7 columns instead of give or take 1000 columns.
 
Tim Jones
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Tim Jones wrote:just so it is clear, there are 7 columns in total with give or take 1000+ rows (values).



Thanks for the clarification. So my suggestion would be to change your array declaration

so that it only has 7 columns instead of give or take 1000 columns.



After editing the column size as suggested, the initial problem has gone away. It was the column size all long. I think for added measure I'm going to go ahead and switch to Abstract Table Model just in case.

Thanks
 
Wendy L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I stand by my comment, what is any user going to do with 1000 rows of data? all they are going to be doing is searching for the rows which are actually relevant to them, or trying to work out summaries.
it may be physically possible with a new table model, but i would be willing to bet it will still run like a dog.

for a technical answer: The data is filtered before the table is created.
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Wendy Gibbons wrote:I stand by my comment, what is any user going to do with 1000 rows of data? all they are going to be doing is searching for the rows which are actually relevant to them, or trying to work out summaries.
it may be physically possible with a new table model, but i would be willing to bet it will still run like a dog.



Here's an example: I have an application which I run very frequently, and its background data consists of trees with about 10,000 nodes each. I'm not running the app because I want to search for particular nodes, they are all potentially relevant. I would never ask the writer of the app (which is also me) to reduce the amount of data I get.

And as for running like a dog... it was starting to get slow when I have about twenty of these trees loaded in memory, but then I upped the available memory to 1 gigabyte and now it's fine.

reply
    Bookmark Topic Watch Topic
  • New Topic