digitalmars.D - Class deallocators
- Arcane Jill (8/30) Jun 08 2004 ..delete is not called!
- Sean Kelly (4/33) Jun 08 2004 This may just be a case where the instance is cleaned up too late for an...
- Arcane Jill (5/7) Jun 08 2004 Thanks for pointing out that possibility, Sean. I hadn't thought of that...
- Regan Heath (5/47) Jun 08 2004 Write those lines to a file instead?
- Ilya Minkov (8/47) Jun 09 2004 In my opinion, this should be put exactly the other way around. There
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...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(). Seanclass 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()?
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...Write those lines to a file instead? ReganIn the following example...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().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()?Sean-- 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