Open ALameLlama opened 5 months ago
I think I reported this Bug on the discord. It's not the validation, it's the model manager, who keeps a copy of every model and this grows unlimited
@noone-silent is this confirmed or it's just a guess? Do you know if someone is looking into it? I'm having memory leak problems in a forever-running CLI script
Yes, this is where you can experience it. We had the same problem, our container crashed, because the memory was only growing. I debugged it and found out, that the ModelsManager keeps every Model and the relations in memory.
So it is confirmed on our side. We overwrite the models to always use a new ModelsManager
public function initialize(): void
{
// Only run this on the first initialization.
// When there are non critical tasks, place it outside of this if.
if ($this->modelsManager instanceof Manager === false) {
$this->useDynamicUpdate(true);
$this->modelsManager = new Manager();
$this->modelsManager->setDI($this->getDI());
}
}
Also you need to overwrite the getRelated
and postSaveRelatedRecords
Methods. This solved our memory Problem.
@maxgalbu If this fixes your issues too, please post it here.
@noone-silent actually, it wasn't models that were leaking for me, I did find another memory leak: https://github.com/phalcon/cphalcon/issues/16571
Describe the bug On a new phalcon project Trying to create models in a loop and the model has a validation function will leak memory
To Reproduce I set up a user model and then added this like in the example
Created a loop like this
Over each model it's still holding a refereance to something
Expected behavior I'm pretty sure this should get GC'd I checked with gc_status() and it looks like the PHP garbage collector is running but it's not freeing this memory
Details