Edit report at http://bugs.php.net/bug.php?id=48781&edit=1

 ID:               48781
 Updated by:       [email protected]
 Reported by:      nate at frickenate dot com
 Summary:          Cyclical garbage collector memory leak
 Status:           Closed
 Type:             Bug
 Package:          Scripting Engine problem
 Operating System: Debian 5.0 kernel 2.6.24-23-xen
 PHP Version:      5.3.0
 Assigned To:      dmitry

 New Comment:

Note that your test and expectation are not completely correct because
the actual garbage collection occurs at undefined moments of time. As
result the memory usage on different iteration will be different. To
avoid this ambiguity add explicit call to gc_collect_cycles() before
printing memory usage.


Previous Comments:
------------------------------------------------------------------------
[2010-04-20 14:50:54] [email protected]

This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.



------------------------------------------------------------------------
[2010-04-20 14:30:38] [email protected]

Automatic comment from SVN on behalf of dmitry
Revision: http://svn.php.net/viewvc/?view=revision&revision=298213
Log: Fixed bug #48781 (Cyclical garbage collector memory leak)

------------------------------------------------------------------------
[2010-04-19 12:37:21] [email protected]

That should have said ...



"So, it is _NOT_ completely losing the items, just not cleaning them
during the 

cycle. At shutdown, they are cleaned."

------------------------------------------------------------------------
[2010-04-19 12:31:56] [email protected]

If the loop is limited to 11111 items, using my code to report the 

construct/use/destruct, the log ends with ...





11108:#3

11109:#3

11110:#3

11111:#3

04999:#3

09999:#3

10000:#3





So, it is completely losing the items, just not cleaning them during the
cycle. 

At shutdown, they are cleaned.

------------------------------------------------------------------------
[2010-04-19 12:27:12] [email protected]

The gc cycle seems to miss the last 2 items on this cycle, but picks up
from the 

last one for the next cycle, so is only actually dropping 1 item per
cycle.



My cycle goes something like this ...



Create and assign #1 to #4999

Create #5000

Destroy #1 to #4998

Assign #5000

Create and assign #5001 to #9999

Create #10000

Destroy #5000 to #9998 --- Skipped #4999

Assign #10000

Create and assign #10001 to #14999

Create #15000

Destroy #10000 to #14998 --- Skipped #9999

etc.



My code changes ...



class User {

    protected

        $profile, $usercount;



    public function __construct ($usercount) {

    echo str_pad($this->usercount = $usercount, 5, '0', STR_PAD_LEFT),
':#1', 

PHP_EOL;

        $this->profile = new UserProfile($this);

    }



   public function __destruct() {

    echo str_pad($this->usercount, 5, '0', STR_PAD_LEFT), ':#3',
PHP_EOL;

   }

}



class UserProfile {

    private

        $user;



    public function __construct ($user) {

        $this->user = $user;

    }

}



for ($userid = 1; ; $userid++) {

    $user = new User($userid);



    echo str_pad($userid, 5, '0', STR_PAD_LEFT), ':#2', PHP_EOL;



// Same code as provided by Nate.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    http://bugs.php.net/bug.php?id=48781


-- 
Edit this bug report at http://bugs.php.net/bug.php?id=48781&edit=1

Reply via email to