polserver/testsuite/pol/testpkgs/funcref/destroyed.src
turleypol 552248917b
Fixed leak when a class/funcref is a global (#887)
* store globals as weakptr in class/funcs to prevent memleak when stored
as global WIP

* let it crash if globals are no longer valid?

* typo

* removed debug prints

* let only the current executor crash

* fixed logic

* added and corrected tests

* cleanup

* use emplace_back

* classes also need to switch to weakptr

* docs
2026-05-27 08:02:19 +02:00

23 lines
634 B
Text

use os;
var dest_glob0 := "dg0";
var dest_glob1 := "dg1";
var dest_glob2 := "dg2";
program destroyed( test_pid )
var res := start_script( ":testfuncref:call-and-send", @DestroyedUserFunc );
GetProcess( test_pid ).SendEvent( struct{ type := "spawned", result := res } );
return 1;
endprogram
function DestroyedUserFunc( use_globals, args... )
var dest_loc1 := True;
var dest_loc2 := "hello local";
if ( use_globals )
dest_glob1 := $"{dest_glob0} {dest_glob1} {dest_glob2} DestroyedUserFunc({args})";
return dest_glob1;
else
return $"{dest_loc1} {dest_loc2} DestroyedUserFunc({args})";
endif
endfunction