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

Implement attemptMemoryReclaim() to reduce memory usage #24

Open
ChristophB opened this issue Dec 1, 2017 · 0 comments
Open

Implement attemptMemoryReclaim() to reduce memory usage #24

ChristophB opened this issue Dec 1, 2017 · 0 comments

Comments

@ChristophB
Copy link
Member

When an Entity is loaded from the DB, it is stored in Drupals cache.
The cache may exceed the allowed maximum memory.

The following function should reclaim memory of entities, which were loaded but are not required anymore.

function attemptMemoryReclaim() {
    // First, try resetting Drupal's static storage - this frequently releases plenty of memory to continue.
    drupal_static_reset();
  
    // Entity storage can blow up with caches so clear them out.
    $manager = \Drupal::entityManager();
    foreach ($manager->getDefinitions() as $id => $definition) {
        $manager->getStorage($id)->resetCache();
    }
    return memory_get_usage();
}
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

1 participant