digitalmars.D - Class deallocators
- Arcane Jill <Arcane_member pathlink.com> Jun 08 2004
- Sean Kelly <sean f4.ca> Jun 08 2004
- Arcane Jill <Arcane_member pathlink.com> Jun 08 2004
- Regan Heath <regan netwin.co.nz> Jun 08 2004
- Ilya Minkov <minkov cs.tum.edu> Jun 09 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
Jun 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
Jun 08 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
Jun 08 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? ReganSean
-- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jun 08 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
Jun 09 2004









Arcane Jill <Arcane_member pathlink.com> 