⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.133
Server IP:
185.119.109.197
Server:
Linux managedhosting.chostar.me 5.15.0-160-generic #170-Ubuntu SMP Wed Oct 1 10:06:56 UTC 2025 x86_64
Server Software:
Apache
PHP Version:
8.1.33
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
usr
/
share
/
ri
/
3.0.0
/
system
/
ObjectSpace
/
View File Name :
define_finalizer-c.ri
U:RDoc::AnyMethod[iI"define_finalizer:ETI""ObjectSpace::define_finalizer;TT:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [ I"EAdds
aProc
as a finalizer, to be called after
obj
;TI"Cwas destroyed. The object ID of the
obj
will be passed ;TI"Das an argument to
aProc
. If
aProc
is a lambda or ;TI"?method, make sure it can be called with a single argument.;To:RDoc::Markup::BlankLine o; ; [I":The return value is an array
[0, aProc]
.;T@o; ; [ I"JThe two recommended patterns are to either create the finaliser proc ;TI"Lin a non-instance method where it can safely capture the needed state, ;TI"Eor to use a custom callable object that stores the needed state ;TI"&explicitly as instance variables.;T@o:RDoc::Markup::Verbatim; [ I"class Foo ;TI"4 def initialize(data_needed_for_finalization) ;TI"g ObjectSpace.define_finalizer(self, self.class.create_finalizer(data_needed_for_finalization)) ;TI" end ;TI" ;TI"? def self.create_finalizer(data_needed_for_finalization) ;TI" proc { ;TI"= puts "finalizing #{data_needed_for_finalization}" ;TI" } ;TI" end ;TI" end ;TI" ;TI"class Bar ;TI" class Remover ;TI"6 def initialize(data_needed_for_finalization) ;TI"H @data_needed_for_finalization = data_needed_for_finalization ;TI" end ;TI" ;TI" def call(id) ;TI"> puts "finalizing #{@data_needed_for_finalization}" ;TI" end ;TI" end ;TI" ;TI"4 def initialize(data_needed_for_finalization) ;TI"W ObjectSpace.define_finalizer(self, Remover.new(data_needed_for_finalization)) ;TI" end ;TI" end ;T:@format0o; ; [ I"=Note that if your finalizer references the object to be ;TI"Efinalized it will never be run on GC, although it will still be ;TI"Crun at exit. You will get a warning if you capture the object ;TI"6to be finalized as the receiver of the finalizer.;T@o;; [ I"class CapturesSelf ;TI" def initialize(name) ;TI"3 ObjectSpace.define_finalizer(self, proc { ;TI"5 # this finalizer will only be run on exit ;TI"% puts "finalizing #{name}" ;TI" }) ;TI" end ;TI" end ;T; 0o; ; [I"NAlso note that finalization can be unpredictable and is never guaranteed ;TI"to be run except on exit.;T: @fileI" gc.c;T:0@omit_headings_from_table_of_contents_below0I"5ObjectSpace.define_finalizer(obj, aProc=proc()) ;T0[ I"(p1, p2 = v2);T@LFI"ObjectSpace;TcRDoc::NormalModule00