0 Replies Latest reply: Feb 11, 2013 10:43 AM by qwerty1 RSS

    TableView cells gobble up my memory

    qwerty1
      Does anyone know how to re-use a tableview cell renderer? I have a table with 50 visible rows and 20 visible columns so fx creates 50*20=1000 instances of TableCell,
      each is around 488b shallow size and around 4030 bytes retained size (as profiler told me) so that makes my table, just the table not counting my data to use over 4 Mb !

      And I need 10 tables in my app.

      Does anyone have any ideas how to reuse cell/renderer or minimize memory usage?

      Any help is greatly appreciated!


      Here is a sample of how I create factory and renderers.

      TableColumn column = new TableColumn(name);
      column.setMinWidth(20);
      column.setCellValueFactory(new PropertyValueFactory<Person, String>(propertyName));
      column.setCellFactory(new MyCellFactory());

      class MyCellRenderer extends TableCell<Person, String>
      {
      public MyCellRenderer()
      {
      super();
      }
      protected void updateItem(String value, boolean empty)
      {
      super.updateItem(value, empty);

      if (!empty)
      {
      setText(value + " *");//this is instead of my real sophisticated operation
      }
      }
      }

      class MyCellFactory implements Callback<TableColumn, TableCell>
      {
      public MyCellFactory()
      {
      }
      public TableCell call(TableColumn p)
      {
      return new MyCellRenderer();
      }
      }