Skip to content

Conversation

@viest
Copy link

@viest viest commented Feb 25, 2022

The view data keeps appending causing memory to increase.

For example.

There is a timed task to send emails, I send 100 emails with different data, the view data length will be 100, the data volume is large but the memory is relatively small, it can easily lead to killed.

Add a method to clean up view data, users can clean up unnecessary data by themselves to protect memory.

for ($index = 0; $index < 100; $index++) {
    /* @var Factory $viewFactor */
    $viewFactor = Mail::getViewFactory();

    $view = $viewFactor->make('email.view', [
        // big data......
    ]);

    // get html
    $data = $view->render();

    /* @var CompilerEngine $viewEngine */
    $viewEngine = $view->getEngine();
    $viewEngine->flushViewData();

    // send mail via raw data
    // ......
}

The view data keeps appending causing memory to increase.

For example.

There is a timed task to send emails, I send 100 emails with different data, the view data length will be 100, the data volume is large but the memory is relatively small, it can easily lead to killed.

```php
        for ($index = 0; $index < 100; $index++) {
            /* @var Factory $viewFactor */
            $viewFactor = Mail::getViewFactory();

            $view = $viewFactor->make('email.view', [
                // ......
            ]);

            // get html
            $data = $view->render();

            /* @var CompilerEngine $viewEngine */
            $viewEngine = $view->getEngine();
            $viewEngine->flushViewData();

            // send mail via raw data
            // ......
        }
```
@freekmurze
Copy link
Collaborator

Could you also document this function in the readme?

@viest
Copy link
Author

viest commented Feb 28, 2022

I described what the function does through comments, does this meet your requirements?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants