July 15, 2012
I make simple learning project and encounter the problem that when my application exits I get access violations (yes, I use windows and moreover - XP version :) ). I don't know the reason of errors, I'm sure that exceptions are thrown by runtime, not my code directly - its occurs right behind/after my code execution. Where can I learn about using of GC ( I think my code don't support gc or how to say it )? Or may be it is a common case, I'm not alone and there is some simple and clear solution?

Thanks in advance
July 15, 2012
On 15-07-2012 17:31, Alexandr Druzhinin wrote:
> I make simple learning project and encounter the problem that when my
> application exits I get access violations (yes, I use windows and
> moreover - XP version :) ). I don't know the reason of errors, I'm sure
> that exceptions are thrown by runtime, not my code directly - its occurs
> right behind/after my code execution. Where can I learn about using of
> GC ( I think my code don't support gc or how to say it )? Or may be it
> is a common case, I'm not alone and there is some simple and clear
> solution?
>
> Thanks in advance

It's really, really hard to say what's wrong from this information. You need to post some reduced test case demonstrating the problem.

-- 
Alex Rønne Petersen
alex@lycus.org
http://lycus.org


July 15, 2012
15.07.2012 22:33, Alex Rønne Petersen пишет:
>
> It's really, really hard to say what's wrong from this information. You
> need to post some reduced test case demonstrating the problem.
>

You're right, it's really hard. But I'd like to learn about using GC only.
Of course I'll try to reduce my project to get simple test demonstrating the problem, but it'll take the time. Although may be I'll solve the problem by myself trying to reduce my project, as it often happens. :)
July 15, 2012
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
July 15, 2012
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

July 15, 2012
On 15-07-2012 17:56, Alexandr Druzhinin wrote:
> class A {
> }
> __gshared A a;
>
>   void main(string[] args) {
>       a = new A;
> }

Seems to work for me? (This use of __gshared is perfectly fine, btw.)

alexrp@alexrp ~/Projects/tests $ cat test.d
class A {
}
__gshared A a;

 void main(string[] args) {
     a = new A;
}
alexrp@alexrp ~/Projects/tests $ rdmd test.d
alexrp@alexrp ~/Projects/tests $

-- 
Alex Rønne Petersen
alex@lycus.org
http://lycus.org


July 16, 2012
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?

July 16, 2012
On 07/15/2012 09: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
>


I experienced this behavior when I was banging on pyd. Culprit was using gc allocated references inside a class destructor, using closures inside a class destructor, or asserting or throwing anything inside a class destructor.
July 16, 2012
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.
July 17, 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.

« First   ‹ Prev
1 2
Top | Discussion index | About this forum | D home