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 for fetched message attachments is never released which results in memory leak #531

Open
robkleinee opened this issue Nov 17, 2024 · 1 comment

Comments

@robkleinee
Copy link

robkleinee commented Nov 17, 2024

A long-running script which fetches and processes messages with attachments from a mailbox with this IMAP package results eventually in a 'memory size of ... bytes exhausted'.

I think this has something to do with the fetched attachments. It seems that these attachments somehow are never released from memory?

A workaround is to set manually the attachments to an empty collection after the attachments are processed.

Code to duplicate the bug (be sure to have emails with attachments in the mailbox)

Package version: 5.5.0
PHP: 8.1.x

$inboxFolder = $client->getFolder('inbox');

while (true) {
    echo 'Memory usage: ' . memory_get_usage() . PHP_EOL;

    $messages = $inboxFolder
        ->messages()
        ->all()
        ->limit(1)
        ->get();

    // Process the messages
}

Workaround

$inboxFolder = $client->getFolder('inbox');

while (true) {
    echo 'Memory usage: ' . memory_get_usage() . PHP_EOL;

    $messages = $inboxFolder
        ->messages()
        ->all()
        ->limit(1)
        ->get();

    // Process the messages

    // Workaround to fix memory issue
    $messages->each(
        function ($message) {
            $message->setAttachments(AttachmentCollection::make([]));
        }
    );
}

Am I doing something wrong? Or is there a memory leak?

Thanks in advance!

PS: It seems like this package is abandoned?

@veroca88
Copy link

I have the same issue!
Package version: 4.1.2
PHP: 8.1.x

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

No branches or pull requests

2 participants