Right now the only places in the SB API where lldb:: ModuleSP instances are destroyed are in SBDebugger::MemoryPressureDetected
(where it's just attempted but not guaranteed) and in SBDebugger::DeleteTarget (which will be removed in D83933).
Tests that directly create an lldb::ModuleSP and never create a target therefore currently leak lldb::Module instances. This triggers the sanity checks in lldbtest that make sure
that the global module list is empty after a test.
This patch adds SBModule::GarbageCollectAllocatedModules as an explicit way to clean orphaned lldb::ModuleSP instances. Also we now
start calling this method at the end of each test run and move the sanity check behind that call to make this work. This way
even tests that don't create targets can pass the sanity check.
This fixes TestUnicodeSymbols.py when D83865 is applied (which makes that the sanity checks actually fail the test).