I usually try to break scripts up into smaller pieces to limit script complexity and the size of the data set.
After running scripts, I run a script called “_RELEASE RAM” which is comprised of two nodes.
A Code block with the number “2” and an addition block which adds 2 + 2.
The first run from the dynamo player can take anywhere from 2-10 seconds. The second run takes maybe 0.5 seconds. This seems to get Revit back up to speed, but I don’t know that it completely clears the RAM…