COM balancing and some fixed leaks #419
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've been doing some hunting in Debug mode and often when closing a session would trigger an assert in wincore.cpp, line 1055. I dug into the MFC code and it led me to this post: https://microsoft.public.vc.mfc.narkive.com/cGo3iW5V/afxmaphwnd-causing-an-assert-why.
Following the comments, I did a little further investigation and found that the
CoInitialize(nullptr)
done by the Windows simulator view is never answered by aCoUninitialize()
. This is supposedly a source of leaks and such.I had also seen there was a class,
ScopedComInitializer
, intended to address this, so I made that a member ofCSimulatorView
and removed the original call. Per the CoInitialize docs, I used the single-threaded apartment type.The assert seems to have gone away when quitting normally. I think exiting while stepping through code might still be able to do it—there is audio code without benefit of the scoped initializer—however, this is a marked improvement. 😄
Also in Debug mode, when quitting via the window's "X" (in Windows), you also get a memory leak report.
I finally decided to track these all down. (This was with some simple applications; maybe something more significant would flush out others.)
A few of these are valid. The audio session manager was never closed (just a pointer, 4 bytes), nor was the simulator analytics Lua context (small allocations, but quite a few of them).
Oddly enough,
Rtt_Allocator
has defeated my efforts to fix. 😃This is reference-counted, but the create / destroy calls are not yet balanced, so it leaks a pointer (4 bytes, again).There are some further "leaks" in audio code: a
std::unordered_set
of thread IDs and some AL config info. These are false positives, though. The memory report is issued before the DLL cleanup that does in fact unload them.I've made notes in the allocator and those two audio bits.
For reference, you should now see something like this in a report:
On this run, allocation
279
was theRtt_Allocator
;177
-180
were thestd::unordered_set
; and95
-96
were the "first" ALConfigBlock
and its name ("general"
).