3v4l.org

run code in 300+ PHP versions simultaneously
<?php class NonLeakingClass { protected $x=[1,2,3,4,5,6,7,8,9,10]; public function __counstruct(){ } } class NonLeakingClass2 { protected $x=[1,2,3,4,5,6,7,8,9,10]; public function __counstruct(){ } } function test($x){ $ret = []; for($i=0;$i<(1022/2)*$x;$i++){ $ret[] = new NonLeakingClass(); $ret[] = new NonLeakingClass2(); } return $ret; } echo "Test empty object memory leakage" . PHP_EOL; // WARNING: Uncomment this line and PHP stops to leak memory on object creation, strange :) for ($h = 1; $h < 5; $h++) { echo "test $h \n\n"; var_dump(memory_get_usage(false)); $a = test($h); unset($a); gc_collect_cycles(); var_dump(memory_get_usage(false)); } exit;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 3
Branch analysis from position: 29
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 3
Branch analysis from position: 29
Branch analysis from position: 3
filename:       /in/lV6mL
function name:  (null)
number of ops:  31
compiled vars:  !0 = $h, !1 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   ECHO                                                     'Test+empty+object+memory+leakage%0A'
   28     1        ASSIGN                                                   !0, 1
          2      > JMP                                                      ->27
   29     3    >   ROPE_INIT                                     3  ~4      'test+'
          4        ROPE_ADD                                      1  ~4      ~4, !0
          5        ROPE_END                                      2  ~3      ~4, '+%0A%0A'
          6        ECHO                                                     ~3
   30     7        INIT_FCALL                                               'var_dump'
          8        INIT_FCALL                                               'memory_get_usage'
          9        SEND_VAL                                                 <false>
         10        DO_ICALL                                         $6      
         11        SEND_VAR                                                 $6
         12        DO_ICALL                                                 
   31    13        INIT_FCALL                                               'test'
         14        SEND_VAR                                                 !0
         15        DO_FCALL                                      0  $8      
         16        ASSIGN                                                   !1, $8
   32    17        UNSET_CV                                                 !1
   33    18        INIT_FCALL                                               'gc_collect_cycles'
         19        DO_ICALL                                                 
   34    20        INIT_FCALL                                               'var_dump'
         21        INIT_FCALL                                               'memory_get_usage'
         22        SEND_VAL                                                 <false>
         23        DO_ICALL                                         $11     
         24        SEND_VAR                                                 $11
         25        DO_ICALL                                                 
   28    26        PRE_INC                                                  !0
         27    >   IS_SMALLER                                               !0, 5
         28      > JMPNZ                                                    ~14, ->3
   37    29    > > EXIT                                                     
   38    30*     > RETURN                                                   1

Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 4
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 4
Branch analysis from position: 16
Branch analysis from position: 4
filename:       /in/lV6mL
function name:  test
number of ops:  18
compiled vars:  !0 = $x, !1 = $ret, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        ASSIGN                                                   !1, <array>
   20     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->13
   21     4    >   NEW                                              $6      'NonLeakingClass'
          5        DO_FCALL                                      0          
          6        ASSIGN_DIM                                               !1
          7        OP_DATA                                                  $6
   22     8        NEW                                              $9      'NonLeakingClass2'
          9        DO_FCALL                                      0          
         10        ASSIGN_DIM                                               !1
         11        OP_DATA                                                  $9
   20    12        PRE_INC                                                  !2
         13    >   MUL                                              ~12     !0, 511
         14        IS_SMALLER                                               !2, ~12
         15      > JMPNZ                                                    ~13, ->4
   24    16    > > RETURN                                                   !1
   26    17*     > RETURN                                                   null

End of function test

Class NonLeakingClass:
Function __counstruct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lV6mL
function name:  __counstruct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E > > RETURN                                                   null

End of function __counstruct

End of class NonLeakingClass.

Class NonLeakingClass2:
Function __counstruct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lV6mL
function name:  __counstruct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E > > RETURN                                                   null

End of function __counstruct

End of class NonLeakingClass2.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.72 ms | 1403 KiB | 20 Q