GC object finalization not guaranteed
Michel Fortin
michel.fortin at michelf.com
Sat Apr 25 05:26:27 PDT 2009
On 2009-04-19 09:10:12 -0400, Daniel Keep <daniel.keep.lists at gmail.com> said:
> Walter Bright wrote:
>> Leandro Lucarella wrote:
>>> Close a connection gracefully for example, I guess (I mean, send a "bye"
>>> packed, not just close the socket abruptly). Same for closing files
>>> writing some mark or something. They can be risky when finalization is
>>> not
>>> deterministic though.
>>
>> Scoped objects should be used for that, not gc.
>
> But you can't tell in a dtor whether you're being destroyed
> deterministically or not. The only safe assumption is that you aren't,
> thus rendering dtors worse than useless.
Actually you could declare your class as scope, that'd make sure every
instance is scope and gets destructed in a timely manner.
Hum, perhaps destructors should only be allowed on scope classes. :-)
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list