In Database.~this() the destructor allocates memory, which causes any program to crash, if the database is destroyed during a garbage collection.
Garbage collection dies badly if you ever allocate memory via GC.malloc while in a destructor, and "throw new Exception" does that. (In particular, garbage collection has to die without a stack trace, because IT can't throw a new Exception). You might be able to (in theory) emplace an exception in malloc'd or previously allocated memory, but otherwise you can't throw exceptions in a destructor. Or do much of anything.
You could use this function to check if you can alloc memory, and just print out a warning error instead of throwing an exception. But I don't know what else in there might be allocating memory.
In Database.~this() the destructor allocates memory, which causes any program to crash, if the database is destroyed during a garbage collection.
Garbage collection dies badly if you ever allocate memory via GC.malloc while in a destructor, and "throw new Exception" does that. (In particular, garbage collection has to die without a stack trace, because IT can't throw a new Exception). You might be able to (in theory) emplace an exception in malloc'd or previously allocated memory, but otherwise you can't throw exceptions in a destructor. Or do much of anything.
You could use this function to check if you can alloc memory, and just print out a warning error instead of throwing an exception. But I don't know what else in there might be allocating memory.