Macaulay2 » Documentation
Packages » Macaulay2Doc » The Macaulay2 language » system facilities » registerFinalizer
next | previous | forward | backward | up | index | toc

registerFinalizer -- register a string that will be displayed when an object is garbage collected

Description

i1 : for i from 1 to 9 do (x := 0 .. 10000 ; registerFinalizer(x, "-- finalizing sequence #"|i|" --"))
i2 : collectGarbage() 
--finalization: (1)[5]: -- finalizing sequence #6 --
--finalization: (2)[8]: -- finalizing sequence #9 --
--finalization: (3)[1]: -- finalizing sequence #2 --
--finalization: (4)[4]: -- finalizing sequence #5 --
--finalization: (5)[7]: -- finalizing sequence #8 --
--finalization: (7)[3]: -- finalizing sequence #4 --
--finalization: (8)[6]: -- finalizing sequence #7 --
--finalization: (9)[2]: -- finalizing sequence #3 --
--finalization: (6)[0]: -- finalizing sequence #1 --

Caveat

This function should mainly be used for debugging. Having a large number of finalizers might degrade the performance of the program. Moreover, registering two or more objects that are members of a circular chain of pointers for finalization will result in a memory leak, with none of the objects in the chain being freed, even if nothing else points to any of them.

See also

Ways to use registerFinalizer:

  • registerFinalizer(Thing,String) (missing documentation)

For the programmer

The object registerFinalizer is a method function.


The source of this document is in Macaulay2Doc/ov_system.m2:1032:0.