Comment #0 by leandro.lucarella — 2010-06-22T19:58:53Z
This is basically the same bug I reported to Tango:
http://www.dsource.org/projects/tango/ticket/1941
I found a couple of bugs in the minimize() function of the GC.
Here is some kind of patch that fixes the bugs (and add a little enhancement), with inline comments (this is found in gc/gcx.d):
---
/**
* Minimizes physical memory usage by returning free pools to the OS.
*/
void minimize()
{
size_t n;
size_t pn;
Pool* pool;
size_t ncommitted;
for (n = 0; n < npools; n++)
{
pool = pooltable[n];
ncommitted = pool.ncommitted;
for (pn = 0; pn < ncommitted; pn++)
{
if (cast(Bins)pool.pagetable[pn] != B_FREE)
break;
}
if (pn < ncommitted)
{
- n++; // n++ is done by the for loop, this skips a pool
continue;
}
pool.Dtor();
cstdlib.free(pool);
cstring.memmove(pooltable + n,
pooltable + n + 1,
(--npools - n) * (Pool*).sizeof);
+ n--; // without this, we are skipping the first moved pool
- minAddr = pooltable[0].baseAddr;
- maxAddr = pooltable[npools - 1].topAddr;
}
+ minAddr = pooltable[0].baseAddr; // there is no point on doing
+ maxAddr = pooltable[npools - 1].topAddr; // this for each moved pool
}
---