File tree Expand file tree Collapse file tree 2 files changed +62
-2
lines changed Expand file tree Collapse file tree 2 files changed +62
-2
lines changed Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ GC 045: Total count persisted when GC is rerun due to destructor call
3
+ --INI--
4
+ zend.enable_gc=1
5
+ --FILE--
6
+ <?php
7
+ class GlobalData
8
+ {
9
+ public static Bar $ bar ;
10
+ }
11
+
12
+ class Value
13
+ {
14
+ public function __destruct ()
15
+ {
16
+ new Bar ();
17
+ }
18
+ }
19
+
20
+ class Bar
21
+ {
22
+ public function __construct ()
23
+ {
24
+ GlobalData::$ bar = $ this ;
25
+ }
26
+ }
27
+
28
+ class Foo
29
+ {
30
+ public Foo $ selfRef ;
31
+ public Value $ val ;
32
+
33
+ public function __construct (Value $ val )
34
+ {
35
+ $ this ->val = $ val ;
36
+ $ this ->selfRef = $ this ;
37
+ }
38
+ }
39
+
40
+ for ($ j = 0 ; $ j < 10 ; $ j ++) {
41
+ for ($ i = 0 ; $ i < 3000 ; $ i ++) {
42
+ new Foo (new Value ());
43
+ }
44
+ }
45
+
46
+ var_dump (gc_status ());
47
+ ?>
48
+ --EXPECT--
49
+ array(4) {
50
+ ["runs"]=>
51
+ int(10)
52
+ ["collected"]=>
53
+ int(25000)
54
+ ["threshold"]=>
55
+ int(10001)
56
+ ["roots"]=>
57
+ int(10000)
58
+ }
Original file line number Diff line number Diff line change @@ -1469,12 +1469,13 @@ static void zend_gc_root_tmpvars(void);
1469
1469
1470
1470
ZEND_API int zend_gc_collect_cycles (void )
1471
1471
{
1472
- int count = 0 ;
1472
+ int total_count = 0 ;
1473
1473
bool should_rerun_gc = 0 ;
1474
1474
bool did_rerun_gc = 0 ;
1475
1475
1476
1476
rerun_gc :
1477
1477
if (GC_G (num_roots )) {
1478
+ int count ;
1478
1479
gc_root_buffer * current , * last ;
1479
1480
zend_refcounted * p ;
1480
1481
uint32_t gc_flags = 0 ;
@@ -1652,6 +1653,7 @@ ZEND_API int zend_gc_collect_cycles(void)
1652
1653
1653
1654
GC_TRACE ("Collection finished" );
1654
1655
GC_G (collected ) += count ;
1656
+ total_count += count ;
1655
1657
GC_G (gc_active ) = 0 ;
1656
1658
}
1657
1659
@@ -1668,7 +1670,7 @@ ZEND_API int zend_gc_collect_cycles(void)
1668
1670
finish :
1669
1671
zend_get_gc_buffer_release ();
1670
1672
zend_gc_root_tmpvars ();
1671
- return count ;
1673
+ return total_count ;
1672
1674
}
1673
1675
1674
1676
ZEND_API void zend_gc_get_status (zend_gc_status * status )
You can’t perform that action at this time.
0 commit comments