Freeing memory after string concatenation

bearophile bearophileHUGS at lycos.com
Tue Dec 23 16:28:55 PST 2008


I am using D1, while you probably use D2. I have compiled the following code with -O -release -inline, with the last DMD 1.x:


import std.stdio: writefln;

void foo(string s1, string s2) {
    string con = s1 ~ s2;
    writefln(con);
}

void main() {
    while(true) {
        string t1 = "Do";
        string t2 = "That";
        foo(t1, t2);
    }
}

After more than two minutes of running I don't see any increase of memory used.
Don't use delete in your code, generally it's not needed.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list