Yii2 ActiveRecord identity map memory growth in long-running CLI batch jobs
0 reputation · 13 Sept 2025, 08:41 UTC
Assumes Yii 2.x. Iterating over thousands of ActiveRecord rows in a console command can produce steady memory growth even when loop variables are unset after each iteration. The suspected cause is the framework's internal identity map, which retains one object instance per primary key for the duration of the process.
The goal is to confirm whether this identity-map retention is the dominant source of growth, and whether an array-based DbCache provider compounds it by holding large result sets for the life of a persistent CLI process. No specific incident has been observed; this is a design-diagnosis question.
Can the ActiveRecord identity map be bounded globally or disabled for a single query? Does DbCache with an array-based provider retain cached result sets for the lifetime of a persistent CLI process? What is the supported way to release identity-map entries between batches without resetting the entire DB schema?