Skip to content
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 when calling toArray() on a saved Mappable model #219

Open
jsdtaylor opened this issue Feb 14, 2018 · 0 comments
Open

Memory leak when calling toArray() on a saved Mappable model #219

jsdtaylor opened this issue Feb 14, 2018 · 0 comments

Comments

@jsdtaylor
Copy link

jsdtaylor commented Feb 14, 2018

Laravel v5.5.34
Eloquence v5.5.1

When writing some API tests for a mapped model, I decided to:

  • use a factory to save a model
  • GET the resource using its ID
  • compare the model's mapped attributes with the json response

When calling $model->toArray() I get OOM errors every time:

$transaction = factory(Transaction::class)->create([
    'user_id' => $I->user->id,
]);
$I->sendGET('api/v1/transactions/'.$transaction->id);
$I->seeResponseCodeIs(HttpCode::OK);
$I->seeResponseContainsJson($transaction->toArray());
PHP Fatal error:  Allowed memory size of 2097152000 bytes exhausted (tried to allocate 20480 bytes) in /
var/www/html/vendor/sofa/hookable/src/Hookable.php on line 261
PHP Fatal error:  Allowed memory size of 2097152000 bytes exhausted (tried to allocate 20480 bytes) in /var/www/html/vendor/codeception/codecep
tion/src/Codeception/Subscriber/ErrorHandler.php on line 96

I was really stumped, but when I fetched the model again, everything worked fine:

$transaction = factory(Transaction::class)->create([
    'user_id' => $I->user->id,
]);

# refetch Transaction model
$transaction = Transaction::findOrFail($transaction->id)->first();

$I->sendGET('api/v1/transactions/'.$transaction->id);
$I->seeResponseCodeIs(HttpCode::OK);
$I->seeResponseContainsJson($transaction->toArray());

# print memory usage
echo "\n".format_byte_size(memory_get_usage());
26.79 mb
@jsdtaylor jsdtaylor changed the title Memory leak when calling toArray() on a saved model Memory leak when calling toArray() on a saved Mappable model Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants