Hi. I created a custom cellfactory which produces potentially many new columns (~100).
Many of the cells will be populated with empty strings (instead of missing values… customer preference).
In the interest of reducing memory consumption, is it OK to create a single instance StringCell emptyStringCell = StringCell("") and reuse that instance for all cells that require an empty string?
I implemented it this way and it seems to work fine, but I’m wondering whether there might be any consequences I’m not aware of, or whether this might be discouraged for some reason.
Thank you for the suggestion, @izaychik63. The Missing Value node would indeed be one way to address the issue. However, we would like to avoid having to always follow our custom node with a Missing Value node, so I’d still be interested in knowing the answer. Kind regards, -Don.
singleton instances don’t seem to be a problem. See e.g. the source code here which does the same: org.knime.core.data.MissingCell.INSTANCE or org.knime.core.data.def.BooleanCell.TRUE.
One thing you may want to consider is that, as soon as a table has been written to disk and read back in, your singleton cell will be replaced by ordinary string cell instances. BooleanCell and MissingCell have custom (de)serialization logic in place to prevent that from happening (see here, for example).