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

Fatal error: Out of memory (allocated 46137344) (tried to allocate 20480 bytes) #202

Closed
kjhatis opened this issue Jan 8, 2018 · 7 comments
Labels

Comments

@kjhatis
Copy link

kjhatis commented Jan 8, 2018

Fatal error: Out of memory (allocated 46137344) (tried to allocate 20480 bytes) in D:\xampp\htdocs\XXXXXX\vendor\ramsey\uuid\src\Codec\StringCodec.php on line 57

``

class UserModel extends Model {

protected $fillable = ['uuid', 'name', 'email', 'password', 'activated'];
protected $table = 'users';
public $timestamps = false;
protected $dataFormats = 'u';


public static function create($data) {
    try {
        $uuid4 = Uuid::uuid4();
        return self::create([
                    'uuid' => $uuid4->toString(),
                    'name' => isset($data['name']) ? $data['name'] : '',
                    'email' => isset($data['email']) ? $data['email'] : throwException("Email Is Required!"),
                    'password' => isset($data['password']) ? $data['password'] : throwException("Password is Required!")  
        ]);
    } catch (\Exception $e) {
        //Log::error($e->getTrace());
        return $e->getTrace();
    }
}

``

Not sure Where is the mistake.

@kjhatis
Copy link
Author

kjhatis commented Jan 8, 2018

Fatal error: Out of memory (allocated 767557632) (tried to allocate 262144 bytes) in D:\xampp\htdocs\LearningGPS\vendor\ramsey\uuid\src\Builder\DegradedUuidBuilder.php on line 51

@tomzx
Copy link

tomzx commented Jan 12, 2018

Most likely you have too much memory allocated elsewhere, and this is just where your program crashes. It's unlikely that uuid is the issue here.

@ramsey
Copy link
Owner

ramsey commented Jan 12, 2018

Is the script that's running when you see this error using a lot of memory for some other processes before it gets to this point?

@kaphert
Copy link

kaphert commented Jan 19, 2018

Your code contains an infinite loop. You are calling self::create() instead ofparent::create().

@ramsey
Copy link
Owner

ramsey commented Jan 19, 2018

@kaphert Since it's a static method, should it be static::create() instead?

@kaphert
Copy link

kaphert commented Jan 19, 2018

This issue is not related to the uuid library.

The code should be:

public static function create($data) {
    try {
        $uuid4 = Uuid::uuid4();
        return parent::create([
                    'uuid' => $uuid4->toString(),
                    'name' => isset($data['name']) ? $data['name'] : '',
                    'email' => isset($data['email']) ? $data['email'] : throwException("Email Is Required!"),
                    'password' => isset($data['password']) ? $data['password'] : throwException("Password is Required!")  
        ]);
    } catch (\Exception $e) {
        //Log::error($e->getTrace());
        return $e->getTrace();
    }
}

This is part of a Laravel Eloquent model. I would not recommend doing value checks and assign UUID like this but that is another issue. It would be better to listen for events like creating or saving and than create the uuid value like:

public static function boot()
{
    parent::boot();

    self::creating(function ($model) {
        if (!$model->uuid) {
            $model->uuid = Uuid::uuid4()->toString();
        }
    });
}

@ramsey
Copy link
Owner

ramsey commented Jan 19, 2018

Ah. I see. I wasn't paying attention to the fact that the code override's the parent's static create() method, so even using static::create() would be problematic, so it must be parent::create().

@kjhatis, please confirm that this fixes your issue.

Thanks, @kaphert!

@ramsey ramsey closed this as completed Jul 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants