GC object finalization not guaranteed
Daniel Keep
daniel.keep.lists at gmail.com
Sat Apr 25 05:52:09 PDT 2009
Michel Fortin wrote:
> 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.
Except that's a pain in the butt to actually use. You can't store them
in other classes or structs and you have to create all objects at the
highest scope they're used. I proposed changes to let scope instances
to be returned from functions and stored in other scope classes to make
them more useful, but that never went anywhere. :P
> Hum, perhaps destructors should only be allowed on scope classes. :-)
Probably, but only assuming scope objects are made more usable.
-- Daniel
More information about the Digitalmars-d
mailing list