Php memory problem

the code is as follows

$num = M ("log")-> where ("date_format (create_time,"%Y-%m") =" $date"")-> count ("id");

    for($i = 0; ($i+5000)<=20000;$i += 5000){

        $datas = M("credit_log")->where("date_format(create_time,"%Y-%m") = "$date"")->limit($i,$i+5000)->select();
        echo $this->convert(memory_get_usage(true))."<br/>";
        unset($datas);
        //sleep(5);
    }
    
    

after several cycles, the memory overflowed. Why did the memory overflow occur? Because the unset function does not free memory?

Feb.28,2021

limit ($iMagne5000)


even if you have destroyed the variables, there are two questions: one, have you freed all your memory? Second, are you sure it doesn't matter if the amount of data is 5000 by 5000? The parameter of limit, 1 is the number from which to start, and the subsequent parameter is how many pieces of data to get.


Hello, we should talk about
according to the PHP garbage collection mechanism. First of all, PHP's garbage collection mechanism is reference counting, and then automatic cleanup is realized. When you assign a variable, PHP does not necessarily apply for a memory address directly, because PHP will have a reserved address space and go back to apply when this space is full. After unset, according to PHP's garbage collection mechanism, it will not be automatically reclaimed immediately, and some unset will retain memory space for a period of time, so it is known that

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1c2cb25-33b1a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1c2cb25-33b1a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?