using GC needs particular skills?

Mike Parker aldacron at gmail.com
Tue Jul 17 04:34:20 PDT 2012


On 7/17/2012 1:27 AM, Alexandr Druzhinin wrote:
> 16.07.2012 9:46, Mike Parker пишет:
>> On 7/16/2012 1:01 AM, Alexandr Druzhinin wrote:
>>> 15.07.2012 22:56, Alexandr Druzhinin пишет:
>>>> 15.07.2012 22:33, Alex Rønne Petersen пишет:
>>>> test case:
>>>>
>>>> class A {
>>>> }
>>>> __gshared A a;
>>>>
>>>>   void main(string[] args) {
>>>>       a = new A;
>>>> }
>>>>
>>>> every time after finishing application I get
>>>> core.exception.InvalidMemoryOperationError
>>>> I suspect the problem is misusing __gshared
>>>
>>> sorry for my hurry - I've localized the problem in the linked libraries,
>>> not in my code. Will find further... what the h*ll
>>> Sorry again
>>>
>>
>> Which libraries are you linking with?
>>
>
> 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.



More information about the Digitalmars-d-learn mailing list