rubberduck-vba/Rubberduck

Fix the Out-Of-Memory issues when running all tests from solution

Closed this issue · 5 comments

Currently, when running all Rubberduck tests, OOM issues start appearing roughly halfway through the test suite (on a 16GB machine). Workaround is to stop test run at that point, then restart the remaining tests.

As mentioned in chat yesterday, make sure your test settings are set to run the tests with a 64 bit procesor architecture. Currently, running all tests consumes a bit more than 3 GB of memory; with a 32 bit process, you only get about 1,3 GB.

The issue seems to be that the VS test runner does not release test objects until all tests have finished.

Some heap analysis I performed on a testrun suggests that the cause of huge memory consumption when running the tests is Listeners attached to VBEditor.SafeComWrappers.VBA.VBComponents.ComponentAdded that keep massive instances of RubberduckParserState alive.

The relevant event listeners were made static with 36835fb, and later modified with a3cd649 and 812d8bd.

A potential fix is to drop the events into the VBComponents instance instead of keeping them static. That should allow the testrunner to more aggressively GC unused ParserState instances and keep memory usage down:

Heap overview


Detailed analysis of objects attached to largest EventHandler

The quick-and-dirty fix would be to just not allow creating mocks/parser states in loops in the tests.

Does anyone still have OOM errors with the current built?

Considered fixed for the purposes of unit-tests. It might be useful to verify the scoping of parser-states has been applied across the board there for later reference