In the past I experienced something similar (See https://forum.keyboardmaestro.com/t/excessive-keyboard-maestro-engine-memory-usage/30175/13)
By creating a cron entry like this:
* * * * * echo $( date ;ps -axm -o rss,comm | grep "Keyboard Maestro Engine" | cut -d ' ' -f 1 )>> ~/Desktop/MemoryLog.txt
You will create a log file that will show the memory usage every minute.
Mon Aug 26 21:23:00 CEST 2024 113072
Mon Aug 26 21:24:00 CEST 2024 113104
Mon Aug 26 21:25:00 CEST 2024 113872
Mon Aug 26 21:26:00 CEST 2024 113312
Mon Aug 26 21:27:00 CEST 2024 113440
If you notice a sudden jump in memory consumption you can then check the file
~/Library/Logs/Keyboard Maestro/Engine.log
to figure out what macro had run at the given time. This should give you more insight to figure out what macro caused it and then hopefully you have enough information that will @peternlewis to fix it.