NPE Microflow Best practice

0
I have a non-persistable entity Month used as a parameter for a Data Source microflow in a DataGrid2.The DS microflow generates a list of non-persistable RangeSelectDate objects for the selected month and returns them for display.The month can be changed dynamically. Whenever the month changes, I clear/delete the previously displayed list before generating a new one.However, I also have a download feature. In the download microflow, when I retrieve RangeSelectDate objects via association from the Month object, I still get old RangeSelectDate objects that were previously displayed for older month selections.It seems that old non-persistable objects remain associated in memory even after clearing/deleting the displayed list.Is this expected behavior for non-persistable entities and DS microflows in Mendix?What is the recommended pattern to:dynamically regenerate non-persistable lists for DataGrid2 displayavoid stale associated objects remaining in memorysupport download/export functionality without accumulating old generated objects?
asked
3 answers
0

Yes,It is the expected behavior in Mendix with non-persistable entities when associations are involved.

NPE are lives in session memory, Not stored in database

Deleting/clearing a list shown in a DataGrid2 does not automatically guarantee that all references/associations to those objects are removed everywhere in memory.


In your scenario Month(NPE), RangeSelectDate (NPE) , InDataGrid2 DS microflow generates new RangeSelectDate objects but Old objects were previously associated to the same Month.

Even if you clear the grid,refresh the list,delete displayed objects,

the old associated objects can still remain reachable through:

existing associations,client state,session cache,references held by widgets/microflows.


Instead of Month --association--> RangeSelectDate list,

change that Month parameter -> DS microflow generates fresh list -> Return directly to DataGrid2 and Download microflow regenerates same list again.


It will works.


It won't store generated NPEs on Month,never rely on association retrieval later

and generate on demand every time.



I Hope it helps.

answered
0

Hi man,


Yes, this is expected the Month → RangeSelectDate association accumulates old NPEs because clearing the displayed list isn't the same as clearing the association.

Simple fix: Stop using the association as your download source. Put the generation logic in a shared sub-microflow:

  • SUB_GenerateRangeSelectDates(Month) : List of RangeSelectDate

Then:

  • DataGrid2 DS microflow → calls the sub-microflow, returns fresh list for display.
  • Download microflow → calls the same sub-microflow for the current Month, exports the fresh list (don't retrieve via association).

This way both always regenerate for the current month, so no stale objects ever pile up.

If you must keep the association: before generating new objects in the DS microflow, retrieve the existing RangeSelectDate list by association from Month and delete it — then generate and re-associate.

Easiest of all: create a new Month object on each month change instead of reusing one. Old associations die with the old Month, and the problem disappears.


I hope this helps



answered
0

Hello,


Yes, this is expected with non-persistable entities. Even if you delete the list shown in DataGrid2, old NP objects can still remain associated in memory during the session.

What usually works better is:

  • retrieve old associated RangeSelectDate objects
  • delete them
  • clear the association from Month
  • create and associate fresh objects again

For download/export, I would avoid relying on previously generated NP objects from the grid. Better to regenerate the data again in the download microflow based on the selected month. That avoids stale objects and memory accumulation issues.

answered