-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak on phalcon 3.0.0 and php 7.0 #12116
Comments
Provide valgrind log please, beacause memory_get_usage() doesn't necessary mean memory leak - it can mean just bad internal phalcon code for php 7 which should be fixed of course. |
After adding all properties in model -- no more problems with memory. But why is no such problem in php 5? |
Beacause as far as i know there is some memory leak in phalcon and php 7, it's known by @andresgutierrez but good that you created an issue |
Sorry, I can't provide valgrind log (I can't install php with --enable-debug) $files = $a->getFiles();
foreach ($files as $file) {
} |
Valgrind should still detect memory leaks, event without |
@dimak08 |
@sergeyklay @Jurigag index.php $loader = new \Phalcon\Loader();
$di = new \Phalcon\Di\FactoryDefault();
$di->set('db', function () use ($di) {/**/});
class File extends \Phalcon\Mvc\Model
{
public function getSource()
{
return 'files';
}
public function initialize()
{
$this->belongsTo('a', 'ModelA', 'id', array('alias' => 'a', 'reusable' => true));
}
}
class ModelA extends \Phalcon\Mvc\Model
{
public function getSource()
{
return 'a';
}
public function initialize()
{
$this->hasMany("id", "File", "a", array('alias' => 'files', 'reusable' => false));
}
}
$a = ModelA::findFirst(['id = :id:', 'bind' => ['id' => 5014387]]);
$files = $a->getFiles();
foreach ($files as $f) {};
echo memory_get_usage() . "\n"; response:
zend_objects.c(162) is emalloc function in: ZEND_API zend_object *zend_objects_new(zend_class_entry *ce)
{
zend_object *object = emalloc(sizeof(zend_object) + zend_object_properties_size(ce));
zend_object_std_init(object, ce);
object->handlers = &std_object_handlers;
return object;
} Valgrind:
Response:
Valgrind:
Response:
|
|
I had the same memory leak even with all properties defined in the model, so not sure it works for the memory leak |
Actually you need setters i think as workaround for now: https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/model.zep#L4171 Try to add properties with setters for now, then reflection shouldn't be used and memory leak not happening. |
We'll try to fix it is as soon as it possible |
Well for me public properties is not an option as I need getters/setters under certain circumstances |
@nsossonko I was mistaken, refresh page, if you have setters and getters then reflections shouldn't even be used at all. |
Well I do have getters and setters...but still see the increase in memory. I'd be interested to hear what others are experiencing with this... |
Then the root of this is somewhere else and it's not related to this issue - you need to provide logs from valgrind or other mem analyzing software. |
When i have setters so reflections are not hitted i don't have memory leak @nsossonko :
class Test2 extends Model
{
protected $a0;
protected $a1;
protected $a2;
protected $a3;
protected $a4;
protected $a5;
protected $a6;
protected $a7;
protected $a8;
protected $a9;
protected $a10;
protected $a11;
protected $a12;
/**
* @return mixed
*/
public function getA0()
{
return $this->a0;
}
/**
* @param mixed $a0
*
* @return Test2
*/
public function setA0($a0)
{
$this->a0 = $a0;
return $this;
}
/**
* @return mixed
*/
public function getA1()
{
return $this->a1;
}
/**
* @param mixed $a1
*
* @return Test2
*/
public function setA1($a1)
{
$this->a1 = $a1;
return $this;
}
/**
* @return mixed
*/
public function getA2()
{
return $this->a2;
}
/**
* @param mixed $a2
*
* @return Test2
*/
public function setA2($a2)
{
$this->a2 = $a2;
return $this;
}
/**
* @return mixed
*/
public function getA3()
{
return $this->a3;
}
/**
* @param mixed $a3
*
* @return Test2
*/
public function setA3($a3)
{
$this->a3 = $a3;
return $this;
}
/**
* @return mixed
*/
public function getA4()
{
return $this->a4;
}
/**
* @param mixed $a4
*
* @return Test2
*/
public function setA4($a4)
{
$this->a4 = $a4;
return $this;
}
/**
* @return mixed
*/
public function getA5()
{
return $this->a5;
}
/**
* @param mixed $a5
*
* @return Test2
*/
public function setA5($a5)
{
$this->a5 = $a5;
return $this;
}
/**
* @return mixed
*/
public function getA6()
{
return $this->a6;
}
/**
* @param mixed $a6
*
* @return Test2
*/
public function setA6($a6)
{
$this->a6 = $a6;
return $this;
}
/**
* @return mixed
*/
public function getA7()
{
return $this->a7;
}
/**
* @param mixed $a7
*
* @return Test2
*/
public function setA7($a7)
{
$this->a7 = $a7;
return $this;
}
/**
* @return mixed
*/
public function getA8()
{
return $this->a8;
}
/**
* @param mixed $a8
*
* @return Test2
*/
public function setA8($a8)
{
$this->a8 = $a8;
return $this;
}
/**
* @return mixed
*/
public function getA9()
{
return $this->a9;
}
/**
* @param mixed $a9
*
* @return Test2
*/
public function setA9($a9)
{
$this->a9 = $a9;
return $this;
}
/**
* @return mixed
*/
public function getA10()
{
return $this->a10;
}
/**
* @param mixed $a10
*
* @return Test2
*/
public function setA10($a10)
{
$this->a10 = $a10;
return $this;
}
/**
* @return mixed
*/
public function getA11()
{
return $this->a11;
}
/**
* @param mixed $a11
*
* @return Test2
*/
public function setA11($a11)
{
$this->a11 = $a11;
return $this;
}
/**
* @return mixed
*/
public function getA12()
{
return $this->a12;
}
/**
* @param mixed $a12
*
* @return Test2
*/
public function setA12($a12)
{
$this->a12 = $a12;
return $this;
}
}
$test = new Test2();
echo memory_get_usage(true).'<br>';
for ($i = 0; $i <= 12; $i++) {
try {
$test->__set("a$i", 'test');
}
catch (Exception $e)
{}
}
echo memory_get_usage(true).'<br>'; But when we check for to example 1000 in loop then memory leak occurs, same as in OP. You need to provide script to reproduce this another memory leak. |
@dimak08 Could you please check the |
I checked and it's fine for me. |
Hi @sergeyklay Thanks, But I have another problem with memory. while (true) {
$model = ModelA::findFirst([
'id = :id:',
'bind' => ['id' => 5014387]
]);
if ($counter == 1000) {
echo bytes(memory_get_usage()) . "\n";
}
if ($counter == 2000) {
echo bytes(memory_get_usage()) . "\n";
}
if ($counter == 3000) {
echo bytes(memory_get_usage()) . "\n";
}
if ($counter == 4000) {
echo bytes(memory_get_usage()) . "\n";
die();
}
$counter++;
$model = null;
} php 5.5 + phalcon 3.0 from apt repository:
php 7.0.9 + phalcon 3.0 from git (branch 3.0.x commit 649f35c):
Adding/removing getter/setters/properties = nothing changes. My mega slow server very long compile new version from sources for valgrind. |
You don't need to compile phalcon/php from soruces for using with valgrind. It should work as it is. Just there will be more information in log or php will detect memory leaks itself. |
@Jurigag Valgrind says that no memory leaks. |
@dimak08 Hello. Thanks for answering. It seems to me this is another problem. Could you please open new issue with script to reproduce (model, table schema and this ^ test, valgrind report if any)? So that we can close this issue |
Ok, thanks |
Memory leak (?) on phalcon 3.0.0 and php 7.0 when using relations between models.
sometimes I got this error:
The text was updated successfully, but these errors were encountered: