[Issue 9433] Deprecate delete

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jan 31 08:49:20 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9433



--- Comment #8 from FG <home at fgda.pl> 2013-01-31 08:49:18 PST ---
(In reply to comment #2)
> Try this: [...]
> I see no differences if I compare this and delete, except that "delete" looks
> nicer. But I have not made a detailed test, like you did. 

Nice, holds steady at 40MB, but there's a catch. When you remove the line
"destruct(a);" and rely on the GC to remove unnecessary A instances, the
program will crash, because GC.free cannot be called during a collection. So I
think it's a bit too dangerous.

OK, let's have a compromise. :)
Delete isn't needed after all and can be removed. Since the problem is mostly
about large arrays only, calling destructors is pointless, so using GC.free is
fine to release those big chunks. The freeing could be hidden in A.clean()
method:

    import std.stdio, core.memory;

    class A {
        ubyte[] _chunk;
        this() { this._chunk = new ubyte[40 * 1024 * 1024]; }
        void clean() {
            GC.free(this._chunk.ptr);
            this._chunk = null;
        }
    }

    void main() {
        for (int i = 0; i < 1000; i++) {
            A a = new A();
            a.clean();
        }
    }

Is this approach OK? It keeps memory footprint 3-4 times smaller on 64-bit and
prevents running out of memory on 32-bit windows.
And I'll stop bugging you about keeping delete.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list