using GC needs particular skills?

Alexandr Druzhinin drug2004 at bk.ru
Tue Jul 17 08:45:08 PDT 2012


17.07.2012 18:34, Mike Parker пишет:
> On 7/17/2012 1:27 AM, Alexandr Druzhinin wrote:
>>
>> The reason were bindings to GeographicLib C++ library written in
>> analogue to Derelict bindings (I used it in my projects too).
>> Now I'm trying to make simple test cases for my trouble.
>
> Bindings based on Derelict will release the shared libraries in a static
> module destructor. So if you are calling any bound functions from inside
> class destructors and letting your objects be cleaned up by the GC, then
> you are guaranteed to get a segfault at exit.
>
> That's usually the cause of the problem you're seeing. And if that is
> indeed the root of your problem, you should never rely on class
> destructors to clean up system resources. You cannot control when they
> will be called.
>

I think you hit the problem. When I removed resources releasing from 
destructors in my bindings the error disappeared too. But frankly I 
didn't understand why it happened :( and how I should free resources 
now. What is I can rely on to clean up system resources?
Definitly I need read the TDPL again...)
Is it because GC may mess calling object destructors and static module 
destructors? Don't GC make difference between them and don't call their 
desctructors in predefined order (module destructors before other 
destructors for example or vice versa)?


More information about the Digitalmars-d-learn mailing list