- be a bit more aggressive with the GC when not running the game loop.

Since most CheckGC calls are within the main game ticker, the engine can accumulate a lot of data when creating/deleting objects in the menu or other UI parts and never manage to collect everything
This commit is contained in:
Christoph Oelckers 2021-10-03 14:01:27 +02:00
commit b4d03501af
4 changed files with 22 additions and 1 deletions

View file

@ -43,6 +43,9 @@ namespace GC
// Number of bytes currently allocated through M_Malloc/M_Realloc.
extern size_t AllocBytes;
// Number of allocated objects since last CheckGC call.
extern size_t AllocCount;
// Amount of memory to allocate before triggering a collection.
extern size_t Threshold;
@ -105,10 +108,15 @@ namespace GC
}
// Check if it's time to collect, and do a collection step if it is.
static inline void CheckGC()
static inline bool CheckGC()
{
AllocCount = 0;
if (AllocBytes >= Threshold)
{
Step();
return true;
}
return false;
}
// Forces a collection to start now.