allow to minimize D GC heap immediatly

This commit is contained in:
Basile Burg 2020-06-12 20:47:01 +02:00
parent e9770a0be0
commit 3cbe5d2471
3 changed files with 6 additions and 4 deletions

View File

@ -18,11 +18,11 @@ export extern(C) void setRtOptions()
//config.gc = "precise"; //config.gc = "precise";
} }
export extern(C) void minimizeGcHeap() export extern(C) void minimizeGcHeap(bool now = false)
{ {
import core.memory : GC; import core.memory : GC;
__gshared ubyte c; __gshared ubyte c;
if (c++ > 31) if (c++ > 31 || now)
{ {
GC.collect(); GC.collect();
GC.minimize(); GC.minimize();

View File

@ -56,9 +56,9 @@ function d_rt_init(): integer; cdecl; external libdexedd_name;
function d_rt_term(): integer; cdecl; external libdexedd_name; function d_rt_term(): integer; cdecl; external libdexedd_name;
// Used to release memroy allocated in external D functions that are called in a thread, // Used to release memroy allocated in external D functions that are called in a thread,
// because managing the GC only works from the main thread. // because managing the GC only works from the main thread.
// Memory is released every 32 calls. // Memory is released every 32 calls unless `now` is true.
// This function must be called from the main thread. // This function must be called from the main thread.
procedure minimizeGcHeap(); cdecl; external libdexedd_name; procedure minimizeGcHeap(const now: boolean = false); cdecl; external libdexedd_name;
// noop // noop
procedure setRtOptions(); cdecl; external libdexedd_name; procedure setRtOptions(); cdecl; external libdexedd_name;
// Demangle a line possibly containing a D mangled name. // Demangle a line possibly containing a D mangled name.

View File

@ -1247,6 +1247,8 @@ begin
if fTempFileName.fileExists then if fTempFileName.fileExists then
sysutils.DeleteFile(fTempFileName); sysutils.DeleteFile(fTempFileName);
minimizeGcHeap(true);
inherited; inherited;
end; end;