<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">I see.  And does anyone report running
      out of memory due to this?  It seems like it would mostly be a
      problem with CTFE, but could be a problem on any large project, I
      suppose.<br>
      <br>
      Dave<br>
      <br>
      <br>
      On 11/10/2012 11:34 PM, Daniel Murphy wrote:<br>
    </div>
    <blockquote
cite="mid:CAMU72LE1sj8XT3TL7wFZYGJOF3kndWadSqRcTLJmtmt54MhVNQ@mail.gmail.com"
      type="cite">This isn't a bug, dmd does not free memory (with some
      exceptions), it assumes a garbage collector is present.<br>
      <br>
      <div class="gmail_quote">On Sun, Nov 11, 2012 at 6:26 PM, David
        Held <span dir="ltr"><<a moz-do-not-send="true"
            href="mailto:dmd@wyntrmute.com" target="_blank">dmd@wyntrmute.com</a>></span>
        wrote:<br>
        <blockquote class="gmail_quote" style="margin:0 0 0
          .8ex;border-left:1px #ccc solid;padding-left:1ex">While
          writing some unit tests for Dsymbol, I noticed that
          Dsymbol::toPrettyChars() leaks almost everywhere.  In the
          simple case where a symbol has no parent, it just returns
          toChars(), which does not leak (at least I don't think it
          does).  However, whenever the symbol has a parent (or many),
          the returned string is composed, which requires that it is
          allocated dynamically (via mem.malloc()). Even though the
          caller owns the string, and even though it is called dozens of
          times, it appears that none of the callers are properly
          disposing of the result.  Unfortunately, it is a bit messy to
          do so, because you must free the string *only* if it has a
          parent, which is a pretty bad implementation leak, IMO.  Here
          is a place where std::string would have worked nicely. ;)<br>
          <br>
          I suspect this has gone unnoticed because A) dmd probably has
          a relatively small memory footprint to begin with or B) most
          invokations of toPrettyChars() are during a call to error(),
          so the compiler is about to quit anyway.  What to do?  Leave
          it alone?  Try to fix it?  Note that fixing it without
          changing toPrettyChars() would require adding 2-3 lines of
          code to almost every call.<br>
          <br>
          Dave<br>
          <br>
          <br>
          P.S.  Incidentally, this bug is one that is not easily caught
          with assertions (where would you place the assert that the
          string was freed?).  Fortunately, it is caught by unit
          testing; but it could also have been caught by documenting
          that the caller owns the string.  This is why you really want
          all 3 approaches to code quality.<br>
          <br>
          _______________________________________________<br>
          dmd-internals mailing list<br>
          <a moz-do-not-send="true"
            href="mailto:dmd-internals@puremagic.com" target="_blank">dmd-internals@puremagic.com</a><br>
          <a moz-do-not-send="true"
            href="http://lists.puremagic.com/mailman/listinfo/dmd-internals"
            target="_blank">http://lists.puremagic.com/mailman/listinfo/dmd-internals</a><br>
        </blockquote>
      </div>
      <br>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
dmd-internals mailing list
<a class="moz-txt-link-abbreviated" href="mailto:dmd-internals@puremagic.com">dmd-internals@puremagic.com</a>
<a class="moz-txt-link-freetext" href="http://lists.puremagic.com/mailman/listinfo/dmd-internals">http://lists.puremagic.com/mailman/listinfo/dmd-internals</a></pre>
    </blockquote>
    <br>
  </body>
</html>