Bug #78933 [NEW]: Presence of a destructor affects garbage collection
| From: | requinix@php.net | Date: | Sun, 08 Dec 2019 21:55:34 +0000 |
| Subject: | Bug #78933 [NEW]: Presence of a destructor affects garbage collection | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-224145@lists.php.net to get a copy of this message | ||
From: requinix
Operating system: Any (Windows?)
PHP version: 7.4.0
Package: *General Issues
Bug Type: Bug
Bug description:Presence of a destructor affects garbage collection
Description:
------------
Discovered during bug #78930. Works in PHP 7.3.
With two classes forming a cyclic reference, one of them doesn't seem to
be GCed properly if the other has a destructor - even if empty. It works
without the destructor.
The only way I've been able to reproduce *and detect* the problem has
been to use ext/pdo_sqlite to open a file, then test that the file is
closed using unlink(). As far as I know, this is only possible to do on
Windows since Linux is supposed to allow deleting files with open
handles.
But this doesn't quite feel like a PDO, SQLite, or Windows issue. I
assume the GC recognizes when there is a destructor that needs to be
invoked, and that affects how it cleans up.
Test script:
---------------
<?php
class Test {
public $base;
public $container;
public function __construct(Container $c) {
$this->container = $c;
$this->base = new PDO("sqlite:base.sqlite", "", "");
}
}
class Container {
public $test;
public function __construct() {
$this->test = new Test($this);
}
// commented: no errors, file deleted
// uncommented: "resource temporarily unavailable", file not deleted
function __destruct() { }
}
new Container();
gc_collect_cycles();
unlink("base.sqlite");
--
Edit bug report at https://bugs.php.net/bug.php?id=78933&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78933&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78933&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78933&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78933&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78933&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78933&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78933&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78933&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78933&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78933&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78933&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78933&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78933&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78933&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78933&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78933&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78933&r=mysqlcfg