Does clearing a list help clearing memory?

If you have a list in a microflow which you then loop over, this list will be kept in memory untill the microflow has ended. That means that if you recursivly iterate this microflow untill you have no more items left to update/remove that each iteration will have a list in its memory untill the last iteration is over. Would it help to empty the list before you enter the new iteration?
1 answers

Clearing a list could but it can also make your microflow slower.

When looking at memory consumption in the Mendix platform it is important to understand that we are talking about two separate memory management systems on top of each other.
The Mendix Platform internal memory, which stores all non-persistent objects and all changed objects.
And the regular Java Garbage collector which cleans up all objects as soon as the Platform is done with them.

The built in Mendix garbage collector will not execute until the end of the microflow. That means that when you change an object, those changes will sit somewhere in memory as well. Obviously there are many optimizations done to prevent this from causing issues but that is a bit much to explain in a single forum post.
For the Mendix garbage collector it makes no difference since the Mx Garbage Collector will not be executed until the end of the microflow.

There is also the Java Garbage Collector. This process runs whenever needed and cleans up all objects that are no longer referenced from memory.
If you remove items from the list it will allow the GC to collect those objects and free memory.

However I can make it even more complicated, clearing a list takes up time and resources from the server/VM. You want to make sure that it's worth these resources. So it is definitely not necessary to clear every list after using it.

When I am building my own loops/recursive microflows, personally I always clear all lists after each iteration. It might not make a difference in all situations bit I try to make it a habit to do this for all recursive microflows.