I'm having a torrid time trying to resolve an issue whereby my total GPU memory consumption keeps rising throughout the course of my application, until the application fails with a DX out of memory exception.
I frequently load large textures, split into texture arrays (of type Texture2D). These are freed using .Dispose() before the next one is loaded, but memory is not seen to be freed when using Process Monitor (specifically, the "Committed GPU Memory" keeps rising with each new allocation).
I freely admit that I do not really know what the Committed GPU Memory metric in Process Monitor is telling me, but it is the case that the application will eventually fail through lack of memory - so the memory leak is real (and always when the memory hits the same amount in PM).
I do have object tracking enabled, and am able to see that no objects remain unaccounted for when the application closes normally (including after a number of texture loads).
I have created a synthetic example which simply allocates a texture and immediately calls Dispose() on a button click. This demonstrates the problem - memory usage increases until the application fails with an out of memory exception.
public void d() { texture = new Texture2D(Renderer.Device, new Texture2DDescription() { Width = 1024, Height = 1024, MipLevels = 1, Format = Format.R8_UNorm, BindFlags = BindFlags.ShaderResource, Usage = ResourceUsage.Default, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, ArraySize = 100, SampleDescription = new SampleDescription(1, 0) }); texture.Dispose(); }
I did read somewhere on this forum that calling Flush on the context might have an effect, and in my synthetic example it does stop the memory build up - but not in my real app (?).
System is Windows 8.1, SharpDX 2.6.3.
Am I missing something really obvious here? I've Googled extensively but I can't find anything that suggests more than a Dispose is required when freeing textures.
thanks, Matt
SetShaderResource(0, null)
followed by Flush to free the memory. Is this the accepted procedure for freeing these references? I was just a little surprised that this doesn't seem well documented - at least, I couldn't find anything that mentioned it. What is the role of Flush here? Thanks. \$\endgroup\$SetShaderResource(0, textureView);
, followed by a dispose of both view and texture andPixelShader.SetShaderResource(0, null);
the example app does not free memory - and eventually keels over. What else could be holding a reference and how to free? Thanks again! (edit unless I call Flush after the dispose - in which case, it "works"). \$\endgroup\$