mirror of https://gitlab.com/basile.b/dexed.git
minimize D GC from main thread directly in the widgets calling D in threads
D memory allocated in the threads was never released
This commit is contained in:
parent
fe566e0115
commit
45dbe09cff
|
@ -9,6 +9,25 @@ import
|
|||
import
|
||||
iz.memory;
|
||||
|
||||
|
||||
extern(C) void setRtOptions()
|
||||
{
|
||||
import core.gc.config : config;
|
||||
config.gc = "precise";
|
||||
}
|
||||
|
||||
extern(C) void minimizeGcHeap()
|
||||
{
|
||||
import core.memory : GC;
|
||||
__gshared ubyte c;
|
||||
if (c++ > 96)
|
||||
{
|
||||
GC.collect();
|
||||
GC.minimize();
|
||||
c = 0;
|
||||
}
|
||||
}
|
||||
|
||||
enum ErrorType: ubyte
|
||||
{
|
||||
warning,
|
||||
|
|
|
@ -11,14 +11,14 @@ import
|
|||
extern(C) const(char)* todoItems(const(char)* joinedFiles)
|
||||
{
|
||||
scope Appender!string stream;
|
||||
scope LexerConfig config = LexerConfig("", StringBehavior.source);
|
||||
scope StringCache cache = StringCache(4096);
|
||||
stream.reserve(32);
|
||||
stream.put("object TTodoItems\ritems=<");
|
||||
foreach (fname; joinedFilesToFiles(joinedFiles))
|
||||
{
|
||||
stream.reserve(256);
|
||||
scope LexerConfig config = LexerConfig("", StringBehavior.source);
|
||||
scope source = cast(ubyte[]) std.file.read(fname);
|
||||
scope StringCache cache = StringCache(optimalBucketCount(source.length));
|
||||
DLexer(source, config, &cache)
|
||||
.filter!(a => a.type == tok!"comment")
|
||||
.each!(t => analyze(t, fname, stream));
|
||||
|
|
|
@ -49,6 +49,12 @@ const
|
|||
{$ENDIF}
|
||||
|
||||
|
||||
// Used to release memroy allocated in external D functions that are called in a thread.
|
||||
// because managing the GC only work from the main thread.
|
||||
// memory is released every 96 calls.
|
||||
procedure minimizeGcHeap(); cdecl; external libdexedd_name;
|
||||
// Select the precise GC
|
||||
procedure setRtOptions(); cdecl; external libdexedd_name;
|
||||
// Necessary to start the GC, run the static constructors, etc
|
||||
procedure rt_init(); cdecl; external libdexedd_name;
|
||||
// Cleanup
|
||||
|
@ -125,6 +131,7 @@ begin
|
|||
end;
|
||||
|
||||
initialization
|
||||
setRtOptions();
|
||||
rt_init();
|
||||
finalization
|
||||
rt_term();
|
||||
|
|
|
@ -874,6 +874,7 @@ begin
|
|||
tree.EndUpdate;
|
||||
if f.isNotEmpty then
|
||||
TreeFilterEdit1.Text := f;
|
||||
minimizeGcHeap();
|
||||
end;
|
||||
|
||||
procedure TSymbolListWidget.smartExpand;
|
||||
|
|
|
@ -489,6 +489,7 @@ begin
|
|||
fillTodoList;
|
||||
finally
|
||||
txt.free;
|
||||
minimizeGcHeap();
|
||||
end;
|
||||
end;
|
||||
|
||||
|
|
Loading…
Reference in New Issue