Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: High level C Date: Fri, 05 Aug 2016 10:34:31 -0700 Organization: None to speak of Lines: 43 Message-ID: References: <87mvlimt9i.fsf@bsb.me.uk> <5793c3cb.1636046@news.xs4all.nl> <65b61a13-a54c-4ade-9168-4d71de86103f@googlegroups.com> <89cbb9bc-51c5-45f0-b0ba-c0d469a0b668@googlegroups.com> <20160731164221.2f1d338d@maxa-pc> <20160805054817.0af37f27@maxa-pc> <20160805183052.2284e4d3@maxa-pc> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="20590"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18OhF0j/MFXRIbeQtdQk/FW" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:jnXL2uqQT3W6daWCA031GozyRGQ= sha1:2zdchHx5VEn1nLYaz4vpAJl2avw= Xref: csiph.com comp.lang.c:91747 Melzzzzz writes: > On Fri, 05 Aug 2016 08:24:18 -0700 > Keith Thompson wrote: >> Melzzzzz writes: >> > On Thu, 04 Aug 2016 19:17:42 -0700 >> > Tim Rentsch wrote: >> >> Something I wanted to mention but didn't work its way into the >> >> flow is how to deal with resources (eg, open files). Any >> >> resource that is needed normally will be given its own object. >> >> When a resource object is allocation, normally it will register >> >> a "finalization hook", a function that is called just before >> >> the object is about to be reclaimed. I think most collectors >> >> these days provide a way to associate finalization hooks with >> >> allocated objects, for exactly this purpose. >> > >> > Wrong. Finalizers are useless for resource management as >> > conservative GC is non deterministic. Finalizers are only good for >> > debugging purposes... >> >> I would imagine that non-deterministic finalization might still be >> useful. For example, if you have an open file associated with some >> object, closing that file *eventually* might be good enough. > > Problem is that GC is not obliged to free all objects at all, let alone > in specific order ;) And if that's a problem, it's a problem. If you're using GC, and it provides finalization hooks, *and* if you have other resources (such as open files) such that you don't care about the timing of freeing them any more than you care about the timing of freeing memory, then the non-determinism won't be a problem. Otherwise, it will. My point is merely that your referring to such finalizers as "useless" is an overstatement. There certainly are cases where they're insufficient. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"