Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8144045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:16:01+00:00 2026-06-06T13:16:01+00:00

I try to browse 15 000 documents in MongoDB. The php usage memory explodes

  • 0

I try to browse 15 000 documents in MongoDB.
The php usage memory explodes whith Doctrine ODM.
I make a sequential script but the memory still grows.

$nbrNoticesTotal = $noticesNbr['count'];
        $page = 0;
        $limit = 500;
        $pt = 0;
        $ptTotal = 0;
        $notices = $dm->getRepository('Notice')->findLimit($page, $limit)->toArray();
        if ($nbrNoticesTotal > 0) {
            while ($ptTotal < $nbrNoticesTotal) {
                if ($pt >= $limit) {
                    unset($notices);
                    $this->getContainer()->get('doctrine.odm.mongodb.document_manager');
                    $page += $limit;
                    $notices = $dm->getRepository('Notice')->findLimit($page, $limit)->toArray();
                    $pt = 0;
                }
                foreach ($notices as $key => $notice) {

                    $pt++;
                    $ptTotal++;
                    //unset($notice);
                    unset($notices[$key]);
                }
            }
        }

Exemple to memory_get_usage() :

2012-06-28 14:53:08.541-defaultLogger-DEBUG Start : 20,339,624
2012-06-28 14:53:10.154-defaultLogger-DEBUG get package : 1 - 64,207,344
2012-06-28 14:53:10.891-defaultLogger-DEBUG pointer time : 64,250,536
2012-06-28 14:53:11.642-defaultLogger-DEBUG pointer time : 64,246,952
2012-06-28 14:53:12.375-defaultLogger-DEBUG pointer time : 64,243,368
2012-06-28 14:53:13.140-defaultLogger-DEBUG pointer time : 64,239,784
2012-06-28 14:53:13.911-defaultLogger-DEBUG pointer time : 64,236,264
2012-06-28 14:53:15.359-defaultLogger-DEBUG get package : 2 - 104,447,576
2012-06-28 14:53:17.259-defaultLogger-DEBUG pointer time : 104,482,168
2012-06-28 14:53:19.013-defaultLogger-DEBUG pointer time : 104,478,584
2012-06-28 14:53:20.771-defaultLogger-DEBUG pointer time : 104,475,000
2012-06-28 14:53:22.650-defaultLogger-DEBUG pointer time : 104,471,416
2012-06-28 14:53:24.575-defaultLogger-DEBUG pointer time : 104,467,840
2012-06-28 14:53:26.081-defaultLogger-DEBUG get package : 3 - 139,016,152
2012-06-28 14:53:29.192-defaultLogger-DEBUG pointer time : 139,046,936
2012-06-28 14:53:32.560-defaultLogger-DEBUG pointer time : 139,043,360
2012-06-28 14:53:35.456-defaultLogger-DEBUG pointer time : 139,039,912
2012-06-28 14:53:38.229-defaultLogger-DEBUG pointer time : 139,036,336

What can i do to clear the memory? (unset doesn’t work)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:16:03+00:00Added an answer on June 6, 2026 at 1:16 pm

    Try to use EntityManager::clear method to tell DC to clear objects.

    Also as far I remember foreach makes copy of the array and unset in foreach loop to unset element from array won’t work – by that I mean the memory usage, try using for instead of foreach.

    Also try using $value = null; Instead of unset becouse unset just tells PHP’s GC that it can remove this from memory – but You don’t know when he gonna do this. There are some topics about unset & null – I can be wrong at this point.

    I hope this will help You.

    Also there can be other place where memory grows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to browse localhost on my HTC Magic. I have connected my device
I have a .swf file that I try to browse to and it loads
I have a service that uses SSL. When I try to browse to the
I am having a problem when I try to browse WCF service (.svc file)
i try to run php processes in background and start this from an php
When I try to browse to favicon.ico, for instance, I get this error: ValueError:
When I try to browse my service.svc file,I keep getting this error. I've enabled
When the internet connection is unavailble, and we try to browse to Gmail when
Using CEF Browser I try to hook to the OnLoadEnd event in order to
From my android code I try with the android browser to access a tomcat

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.