<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 11 Aug 2010, at 23:35, Seth Grover wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Monaco; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">1. The default FPC heap manager uses one heap per thread, right?<br></span></blockquote><div><br></div>Yes.</div><div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Monaco; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">2. When a thread is started via, for example, BeginThread<br>(<a href="http://www.freepascal.org/docs-html/rtl/system/beginthread.html">http://www.freepascal.org/docs-html/rtl/system/beginthread.html</a>) this<br>heap, as well as all other threadvars in my code and the rtl code, is<br>setup and initialized automatically, correct?<br></span></blockquote><div><br></div><div>Yes.</div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Monaco; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">3. When this thread exits (in the example of using BeginThread, when<br>the TThreadFunc function passed in to BeginThread terminates) the heap<br>for that thread, in addition to the other threadvars, are<br>automatically disposed, correct?<br></span></blockquote><div><br></div><div>Only the already freed blocks that are still around are automatically disposed, because allocated blocks may still be referenced by other threads. The memory reserved for holding threadvars is indeed freed.</div><br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Monaco; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">The reason I ask is that I have a program (which executes a lot of<br>worker threads via BeginThread) which is experiencing increasing<br>memory usage. heaptrc does not indicate that there are any leaks, but<br>it's a fairly complex program (we have some units where we're getting<br>memory from libc directly, don't ask) so I'm not even supposing at<br>this point that the increasing memory belongs to the FPC heaps at all,<br>but I'm just trying to make sure I understand everything that's going<br>on before I go making assumptions about where the memory allocation is<br>coming from.<br></span></blockquote></div><br><div>You can add the "cmem" unit to your uses clause and see whether the memory ballooning still happens. If that solves the problem, then the problem is related to the FPC heap manager, otherwise it isn't. If it does not solve the problem, compile everything with -gv and run the program under Valgrind (in case you are under Linux or Mac OS X).</div><div><br></div><div><br></div><div>Jonas</div></body></html>