php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76883 After creating every 1024th objects php not freeing up all memory
Submitted: 2018-09-14 14:56 UTC Modified: 2018-09-17 06:15 UTC
From: toma dot zoltan at bitninja dot io Assigned:
Status: Duplicate Package: Performance problem
PHP Version: Irrelevant OS: any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: toma dot zoltan at bitninja dot io
New email:
PHP Version: OS:

 

 [2018-09-14 14:56 UTC] toma dot zoltan at bitninja dot io
Description:
------------
I have a long running daemon script, which could create thousands of object every 5 minutes. I tried to free them, but memory was still used by the process.

An example script: https://3v4l.org/5ap4Z

It doesn't matter if class is empty. Or one or multiple class instances are used by the test.




Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-16 06:55 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2018-09-16 06:55 UTC] nikic@php.net
Duplicate of bug #33487.

The object store will use 8 bytes * next_power_of_two(max_number_of_objects_alive_at_the_same_time). Because object store buckets are reused when objects are destroyed, you usually do not need to worry about this. It's a one-time cost of creating many objects, not a leak that will be incurred for every object.
 [2018-09-16 14:16 UTC] toma dot zoltan at bitninja dot io
Thank you for your reply. Tried to find similar issues, but missed 33487 ticket.

Is there any way in cli enviroment to free all unused memory? (Beside restarting the process).

Sometimes a process, which runs one or two week in a row can consume 500+ MB of RAM.
 [2018-09-17 06:15 UTC] nikic@php.net
If PHP ends up using 500 MB of memory, it is very likely not due to this issue. You'd have to create more than 60 million objects that are *simultaneously live* to reach an object store of that size.

While the problem you are seeing can be due to a leak in PHP itself, the most common cause of "leaks" in long-running PHP processes are libraries that were not designed with this use-case in mind and "leak" memory in the form of caches that are never released -- say a static class property with an array which is filled, but never emptied. I'm not sure if there is an easy way to track down the cause. Maybe a memory profiler like https://github.com/arnaud-lb/php-memory-profiler could be of use.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 04 18:01:31 2024 UTC