I’m trying to get a good automated test up and running to catch memory leaks. I’m using MallocLeakDetection, and I’m running into a few issues. I’m wondering what the intended way to catch leaks are, or what solutions to our issues are.
The way we’re trying to catch leaks, roughly, is that we’re loading a level FOO up(load #1), then loading it up again(load #2), then loading it up again(load #3), and then printing out any leftover memory allocations from load #2. We don’t print allocations from load #1 because we don’t care about things done on initial load, and we can’t print allocations from load #3 because, of course, they’re still allocated. (I did have to modify FMallocLeakDetection::FCallstackTrack operator== to also compare frame numbers so I can track which load they’re from)
When we did that we of course got some spurious “leaks”. For instance, an array in GObjectHash could resize during load #2, and although the object was later destroyed, the memory showed allocated during that time. We addressed that by removing all GObjectHash allocations from the MallocLeakDetection system right before dumping the callstacks.
That still left us with a few apparently spurious leaks.
In FShader::RegisterSerializedResource we load the shaders for the level, unless they’re already loaded. We’d expect that either loading FOO 3 times in a row would only load the shaders the first time(and catch that they were used in the new level before unloading them), or would load the shaders all 3 times(unloading them for each level before loading the next). In practice, it seems to be arbitrary depending on timing, so sometimes shaders are loaded in load #2 and kept around through load #3, thus showing as a “leak” although they are not.
Also, depending on when the scene renderer is shut down, we sometimes have FD3D11UniformBuffer allocations left over from load #2 (even if we wait until load #4 to print them out)
This doesn’t make the leak detection useless to us - I can still manually look for anything else in the callstacks, but it would be nice if we could get a “pristine” setup so that we could treat any apparent leak as an error(and so I wouldn’t even have to track callstacks to spot them initially - which definitely slows down leak detection)
So…
- What’s the intended way to track down leaks?
- Is there a way to get the FShaders to either stay loaded long enough for the new level to see which ones it also needs or to go away reliably early and just reload them for the new level?
- Is there a good way to sync up the render thread such that I can either reliably keep the FD3D11UniformBuffer allocations around between levels or reliably free them?