<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html><body>
<p>On 18 dec '11, Jonas Maebe wrote:</p>
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%"><!-- html ignored --><!-- head ignored --><!-- meta ignored -->
<pre>On 18 Dec 2011, at 14:04, <a href="mailto:dhkblaszyk@zeelandnet.nl">dhkblaszyk@zeelandnet.nl</a>wrote:</pre>
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%">mytest^.name := Format('%s.%.3d', ['name', 1]); This assigns 'name.001' to the pointer variable but causes a memleak. If I assign the same value as string constant no memleak occurs, so it must be something related to format.</blockquote>
<pre>It's related to
a) the type of "name" (I assume it's an ansistring or unicodestring)
b) how you free the memory to which mytest points
If you use freemem or reallocmem, then you will get a memory leak because freemem/reallocmem do not finalize the memory before freeing it. You have to manually call finalize() on the records inside that memory block prior to freeing them via freemem/reallocmem. dispose on the other hand will finalize the freed memory automatically.
Jonas_______________________________________________
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal">http://lists.freepascal.org/mailman/listinfo/fpc-pascal</a>
</pre>
</blockquote>
<p>It was an ansistring indeed, and finalize did the trick! Thanks for your help. How does New and Dispose work btw? Do they use RTTI to call finalize appropriatly? I tried searching the New and Dispose implementations in the RTL sources, but I just could not find them. What unit are they in?</p>
<p> </p>
<p>Regards, Darius</p>
</body></html>