Merge: Finalizing Nit objects on garbage collection
authorJean Privat <jean@pryen.org>
Wed, 13 Aug 2014 13:46:43 +0000 (09:46 -0400)
committerJean Privat <jean@pryen.org>
Wed, 13 Aug 2014 13:46:43 +0000 (09:46 -0400)
commita1dd75c1d41f3310c36de01c51dc4d2d4cd4666a
treeb697d789670027a8bb803b11a0fddf1dc2a103b4
parentd3f1f0fe93c7e318dec7a500c20f5b8df35659ba
parenta8185351d26e33465a5fd2fe6343e620daa94858
Merge: Finalizing Nit objects on garbage collection

Rules for finalizable objects:

* They must be a standard Nit class (not an extern, nor a universal).
* They must not have any cycles, or else they won't be finalized.
* In practice, they should be used on small Nit objects acting as a thin layer around a resource. In other words, it is to be used in the Nity layer.
* `finalize` may be invoked more than once, and the underlying resources may also be used by other instances. This must be considered when implementing `finalize`.
* The finalizer will be called on garbage collection. It can be forced with `sys.force_garbage_collection`.
* When attempting to aquire a limited resource (for example, a file description) if you hit the limit, it is a good practice to force the garbage collection and try again.

Pull-Request: #659
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Frédéric Vachon <fredvac@gmail.com>
src/abstract_compiler.nit