Dynamic array leak?
Meta via Digitalmars-d
digitalmars-d at puremagic.com
Mon Aug 14 08:57:49 PDT 2017
On Saturday, 12 August 2017 at 08:16:56 UTC, Temtaime wrote:
> Collect - is a hit to the GC, not an order. It can ignore this
> request.
As far as I can tell, it is an order. From the GC code[1]:
void collect() nothrow
{
fullCollect();
}
...
size_t fullCollect() nothrow
{
debug(PRINTF) printf("GC.fullCollect()\n");
// Since a finalizer could launch a new thread, we always
need to lock
// when collecting.
static size_t go(Gcx* gcx) nothrow
{
return gcx.fullcollect();
}
immutable result = runLocked!go(gcx);
version (none)
{
GCStats stats;
getStats(stats);
debug(PRINTF) printf("heapSize = %zx, freeSize =
%zx\n",
stats.heapSize, stats.freeSize);
}
gcx.log_collect();
return result;
}
...
//Gcx.fullcollect
size_t fullcollect(bool nostack = false) nothrow
{
MonoTime start, stop, begin;
if (config.profile)
{
begin = start = currTime;
}
debug(COLLECT_PRINTF) printf("Gcx.fullcollect()\n");
//printf("\tpool address range = %p .. %p\n", minAddr,
maxAddr);
{
// lock roots and ranges around suspending threads
b/c they're not reentrant safe
rangesLock.lock();
rootsLock.lock();
scope (exit)
{
rangesLock.unlock();
rootsLock.unlock();
}
thread_suspendAll();
prepare();
if (config.profile)
{
stop = currTime;
prepTime += (stop - start);
start = stop;
}
markAll(nostack);
thread_processGCMarks(&isMarked);
thread_resumeAll();
}
if (config.profile)
{
stop = currTime;
markTime += (stop - start);
Duration pause = stop - begin;
if (pause > maxPauseTime)
maxPauseTime = pause;
start = stop;
}
ConservativeGC._inFinalizer = true;
size_t freedLargePages=void;
{
scope (failure) ConservativeGC._inFinalizer = false;
freedLargePages = sweep();
ConservativeGC._inFinalizer = false;
}
if (config.profile)
{
stop = currTime;
sweepTime += (stop - start);
start = stop;
}
immutable freedSmallPages = recover();
if (config.profile)
{
stop = currTime;
recoverTime += (stop - start);
++numCollections;
}
updateCollectThresholds();
return freedLargePages + freedSmallPages;
}
1.
https://github.com/dlang/druntime/blob/master/src/gc/impl/conservative/gc.d
More information about the Digitalmars-d
mailing list