August 25, 2004 If I'm not being retarded than I might have found a bug or something | ||||
---|---|---|---|---|
| ||||
private import std.stream; class foo { public: // Also streams etc File bar; this(char[] fn) { bar = new File(fn); } ~this() { bar.close(); } } int main(char[][] args) { // errors on runtime foo gen = new foo("thisfile.d"); // runs File bar; bar = new File("thisfile.d"); return 0; } |
August 25, 2004 Re: If I'm not being retarded than I might have found a bug or something | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joey Peters | Joey Peters wrote:
> private import std.stream;
>
> class foo {
> public:
> // Also streams etc
> File bar;
> this(char[] fn) {
> bar = new File(fn);
> }
> ~this() {
> bar.close();
> }
> }
>
> int main(char[][] args) {
> // errors on runtime
> foo gen = new foo("thisfile.d");
> // runs
> File bar;
> bar = new File("thisfile.d");
> return 0;
> }
This is a pretty well known problem with garbage collection. When the program terminates, everything has to be destroyed, but it isn't always possible to destroy everything in the correct order, (a correct order may not even exist in the case of circular references) so destructors that access other objects inevitably run the risk of having a reference to a destroyed object.
-- andy
|
Copyright © 1999-2021 by the D Language Foundation