framework: DB memory leak (querylog disabled)

Problem description

With certain Fluent queries, laravel is leaking memory.

When I do:

\DB::connection()->disableQueryLog();
for($i= 0; $i<10000000;$i++) {
    \DB::table('test')->insert(['somefield' => $somestring ]);
}

…memory usage is growing linear.

When I perform exactly the same query, but using PDO directly:

for($i= 0; $i<10000000;$i++) {
    $query = "insert into `test` (`somefield`) values ('{$somestring}')";
    \DB::connection()->getPdo()->query($query);
}

…memory usage is constant, no problems.

Therefore, I think there must be some kind of leak in Fluent. I tried to locate the problem, but didn’t find it yet.

Reproduction

Create command file in /app/commands/Leaktest.php http://pastebin.com/LJUbaYfp

Register command in app/start/artisan.php

Artisan::add(new Leaktest);

Create table in database:

CREATE TABLE `test` (
    `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
    `somefield` varchar(255) DEFAULT NULL,
     PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Run commands in CLI:

$ art leaktest leak_example
#executions = 10000 - mem: 16523992
#executions = 20000 - mem: 23295240
#executions = 30000 - mem: 29935360
#executions = 40000 - mem: 36837608
#executions = 50000 - mem: 43477728
#executions = 60000 - mem: 50117848
#executions = 70000 - mem: 57282248
#executions = 80000 - mem: 63922368
#executions = 90000 - mem: 70562480
READY
Ready

$ art leaktest noleak_example
#executions = 10000 - mem: 9402032
#executions = 20000 - mem: 9402064
#executions = 30000 - mem: 9402064
#executions = 40000 - mem: 9402064
#executions = 50000 - mem: 9402064
#executions = 60000 - mem: 9402064
#executions = 70000 - mem: 9402064
#executions = 80000 - mem: 9402064
#executions = 90000 - mem: 9402064
READY
Ready

I’m usin updated

 "laravel/framework": "4.0.*",

Anyone a clue of the cause of this memory leak?

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Reactions: 3
  • Comments: 16 (9 by maintainers)

Commits related to this issue

Most upvoted comments

I resolved my memory leak by disabling https://github.com/barryvdh/laravel-debugbar, even tho I did disableQueryLog, debugbar was probably still logging my queries.

I see documentation states

DB::connection()->disableQueryLog();

However, I always use

DB::disableQueryLog();

Can you try that? (May be this is a mistake in documentation?)