Thread overview
Class deallocators
Jun 08, 2004
Arcane Jill
Jun 08, 2004
Sean Kelly
Jun 09, 2004
Arcane Jill
Jun 09, 2004
Regan Heath
Jun 09, 2004
Ilya Minkov
June 08, 2004
In the following example...

>       class A
>       {
>           new(uint n)
>           {
>               printf("hello world\n");
>               return malloc(n);
>           }
> 
>           delete(void* p)
>           {
>               printf("goodbye world\n");
>               free(p);
>           }
> 
>           int x; // Just so there's something to be allocated
>       }
> 
>       int main(char[][] args)
>       {
>           A a = new A;
>           return 0;
>       }

..delete is not called!

Now, I understand about lazy destruction. (Sort of). But the manual clearly states: "the deallocator is called with a pointer to the class instance after the destructor (if any) for the class is called".

So I would expect lazy destruction to omit calling the destructor - but why does it omit calling delete()?

Jill


June 08, 2004
In article <ca5gt8$4t1$1@digitaldaemon.com>, Arcane Jill says...
>
>In the following example...
>
>>       class A
>>       {
>>           new(uint n)
>>           {
>>               printf("hello world\n");
>>               return malloc(n);
>>           }
>> 
>>           delete(void* p)
>>           {
>>               printf("goodbye world\n");
>>               free(p);
>>           }
>> 
>>           int x; // Just so there's something to be allocated
>>       }
>> 
>>       int main(char[][] args)
>>       {
>>           A a = new A;
>>           return 0;
>>       }
>
>..delete is not called!
>
>Now, I understand about lazy destruction. (Sort of). But the manual clearly states: "the deallocator is called with a pointer to the class instance after the destructor (if any) for the class is called".
>
>So I would expect lazy destruction to omit calling the destructor - but why does it omit calling delete()?

This may just be a case where the instance is cleaned up too late for anything to print to the screen.  All bets are off once execution has left main().


Sean


June 09, 2004
In article <ca5je8$8m5$1@digitaldaemon.com>, Sean Kelly says...
>
>This may just be a case where the instance is cleaned up too late for anything to print to the screen.  All bets are off once execution has left main().

Thanks for pointing out that possibility, Sean. I hadn't thought of that. However, while it *MAY* be many things, this an arena in which guesswork is not an option. I need an answer from the man who knows.

Arcane Jill


June 09, 2004
On Tue, 8 Jun 2004 23:51:37 +0000 (UTC), Sean Kelly <sean@f4.ca> wrote:
> In article <ca5gt8$4t1$1@digitaldaemon.com>, Arcane Jill says...
>>
>> In the following example...
>>
>>>       class A
>>>       {
>>>           new(uint n)
>>>           {
>>>               printf("hello world\n");
>>>               return malloc(n);
>>>           }
>>>
>>>           delete(void* p)
>>>           {
>>>               printf("goodbye world\n");
>>>               free(p);
>>>           }
>>>
>>>           int x; // Just so there's something to be allocated
>>>       }
>>>
>>>       int main(char[][] args)
>>>       {
>>>           A a = new A;
>>>           return 0;
>>>       }
>>
>> ..delete is not called!
>>
>> Now, I understand about lazy destruction. (Sort of). But the manual clearly
>> states: "the deallocator is called with a pointer to the class instance after
>> the destructor (if any) for the class is called".
>>
>> So I would expect lazy destruction to omit calling the destructor - but why does
>> it omit calling delete()?
>
> This may just be a case where the instance is cleaned up too late for anything
> to print to the screen.  All bets are off once execution has left main().

Write those lines to a file instead?

Regan

>
> Sean
>
>



-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
June 09, 2004
In my opinion, this should be put exactly the other way around. There should be a guarantee that a destructor gets called at some point for each object (whenever - at garbage collection or at process exit). And on the other hand, class allocators are there only to manage memory, which gets reliably reclaimed by the OS on exit, so the delete need not be necessarily called.

-eye

Arcane Jill schrieb:

> In the following example...
> 
> 
>>      class A
>>      {
>>          new(uint n)
>>          {
>>              printf("hello world\n");
>>              return malloc(n);
>>          }
>>               delete(void* p)
>>          {
>>              printf("goodbye world\n");
>>              free(p);
>>          }
>>               int x; // Just so there's something to be allocated
>>      }
>>           int main(char[][] args)
>>      {
>>          A a = new A;
>>          return 0;
>>      }
> 
> 
> ..delete is not called!
> 
> Now, I understand about lazy destruction. (Sort of). But the manual clearly
> states: "the deallocator is called with a pointer to the class instance after
> the destructor (if any) for the class is called".
> 
> So I would expect lazy destruction to omit calling the destructor - but why does
> it omit calling delete()?
> 
> Jill
> 
>