You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
public function validation()
{
$validator = new Validation();
$validator->add(
'email',
new Uniqueness(
[
'message' => 'The customer email must be unique',
]
)
);
return $this->validate($validator);
}
Over each model it's still holding a refereance to something
Took 0.0199 seconds. Used 1.6799M memory
Took 0.0182 seconds. Used 1.6803M memory
Took 0.0185 seconds. Used 1.6806M memory
Took 0.0182 seconds. Used 1.681M memory
...
Took 0.0179 seconds. Used 1.7147M memory
Took 0.0181 seconds. Used 1.715M memory
Took 0.0181 seconds. Used 1.7154M memory
Took 0.0185 seconds. Used 1.7158M memory
Took 0.0181 seconds. Used 1.7161M memory
Took 0.0187 seconds. Used 1.7165M memory
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
Phalcon version: 5.6.1
PHP Version: 8.2.16
Operating System: Ubuntu
Installation type: Downloaded via git releases
Server: Apache
Other related info (Database, table schema): MariaDB
The text was updated successfully, but these errors were encountered:
@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
publicfunctioninitialize(): 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 = newManager();
$this->modelsManager->setDI($this->getDI());
}
}
Also you need to overwrite the getRelated and postSaveRelatedRecords Methods. This solved our memory Problem.
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
The text was updated successfully, but these errors were encountered: