GC object finalization not guaranteed

Don nospam at nospam.com
Sat Apr 18 22:35:55 PDT 2009


Leandro Lucarella wrote:
> Don, el 18 de abril a las 23:43 me escribiste:
>>>> I don't understand why D even has finalizers. Can they do anything useful?
>>> Yes. I use them to manage GPU memory/resources. Another are wrapper classes around manually allocated arrays (to avoid the false pointer problem with very 
>>> large arrays). Both of these examples don't require finalization at program termination (unlike file handles/sockets, etc)
>> OK, those both make perfect sense -- they are both memory issues. It still seems that gc is perfect for memory, but no good for anything else.
> 
> Well, you mean for resources the OS free for you at program end, right?
> For other resources is not useful because the not guaranteed finalization
> (if you don't have the OS to cover your ass, the GC won't either with this
> limitation).

No, that's not what I mean at all. I actually think it's a good thing 
that the GC doesn't call finalizers at the end -- making it obvious that 
you shouldn't be using it for resource management.
> 
> I think shared memory is an example of memory resource that's not freed by
> the OS on program exit.

Really? That sounds like an OS memory leak. Security issue, too: run 
your program, allocated shared memory, then exit. Repeat until all 
memory is exhausted.



More information about the Digitalmars-d mailing list