After a very fruitful discussion I've rewritten my suggested GC API. Comments please. Is this the path we should be going down? What needs more work? What needs clarification? Have I totally lost the plot?
=pod =head1 NAME GC - The interface to the runtime Garbage collector. =head1 SYNOPSIS class Philosopher is GC::timely { has Fork::Lock $.lfork; has Fork::Lock $.rfork; method dine { $.lfork.grab; $.rfork.grab; ... } method DESTORY { $.rfork.release; $.lfork.release; } } my $long_lived_configuration_verbal_that_dosnt_need_much_checking is GC:tardy; my @pantheon of God is GC::immortal; sub draw ($display,@frames) { no GC::delay; # Slowing down to check garbige would upset our little # animation. for @frames -> {$display.show($_)} } =head1 ADJECTIVES The GC API supplies the following adjectives. =over =item GC::timely Requests timely destruction, that is the object is collected as soon as it is no longer visable. Uses for this taint are to ensure release of expencive resources, and to support porting of Perl5 code that expects timely destruction. =item GC::tardy Indercates to the GC the object is long lived and unlikely to leave program visability. GC's may use this infomation for optimization, for example generational GC's could artificially age object's marked as tardy. =item GC::immortal Prevents collection of this object even when it has passed out of visability. # Is this even a good idea? It may be usefull for FFI. Though its # clearly a heavy wizardy type of thing. If nobody thinks it may be # usefull I think this dangerous beast can be removed even before it # sees the light of day. =item GC::keystone Indercates to the GC the objects that this object has references to are only referenced by this object. Hence if this object is no longer visible then all of the objects that this object refers to are also no longer visable. GC's may use this infomation for optimization. The behavour of the GC when encountering an object that is marked keystone but does not have the keystone property is unspecified, and likely to be inconsistent. =back The Adjectives can be used meaningfully in the following ways. =over 4 =item As a scalar variable taint. my $item is GC::timely; Whatever is stored within the scalar verable requires timely collection. =item As a taint on a collection. my @array is GC::timely; Each member of the @array requires timely collection. =item As a taint on a value. "A string" is GC::timely; # Or should this be C<but CG:timely> ? {a => "hash"} is GC::timely; # corrections/confirmation please. The string/hash requires timely collection. =item As a taint on a class or a role class Philosopher is GC::timely {...} The Philosopher object requires timely collection. =item As a taint on a sub declaration. sub ($x) is GC::timely {...} The closure created by this sub requires timely collection. =item As a Pragma use GC::timely; Every memory consuming object declared in this lexical scope requires timely collection =back =head1 PRAGMAS =over =item no GC::delay / use GC::delay Requests that the GC avoid CPU intensive operations while the program is within this lexical scope. GC's that don't induce delays may ignore this. use GC::delay relaxes the request with in its lexical scope. =back =head1 SUBS =over =item sub GC::delay(+Int|u $depth=1 --> Int|undef) {...} Requests that GC's with CPU interacting operations run at this time. For example a this will trigger a mark and sweep style GC's mark and sweep operation. GC::delay will cause a delay even in blocks marked no GC::delay. The meaning of the $depth is for the most part implementation specific, with the following limmitations. =over =item $depth==0 Requests an optional GC run. That is the CG may run if the GC thinks its necessary ( This is equiverlent to {use GC::delay} ). =item $depth==1 Requrests a normal GC run. =item $depth>1 Requrests a more intensive GC run, with higher values implying greater intensiveness. =back GC::delay may return the number of bytes freed. =item sub GC::type(--> Str) {...} Returns a string interacting the type of GC being used. =back =head1 METHODS =over =item method GC::new(::Class $class: --> GC) {...} Returns a GC object permitting implementation specific requests. =back =cut -- Please excuse my spelling as I suffer from agraphia. See http://dformosa.zeta.org.au/~dformosa/Spelling.html to find out more. Free the Memes.