Hi, I'm developing an enterprise (not game) app based on Metal API, and I have critical issue: Metal textures aren't releasing it's memory after dispose, what is leading to extensive memory leaks and app crashes.
I've made some investigation and achieved strange results, which I can't explain.
Case 1:
class SomeClass : IDisposable
{
private IMTLTexture _metalTexture;
public void CreateTexture()
{
_metalTexture = device.CreateTexture(textureDescriptor);
}
public void Dispose()
{
_metalTexture.Dispose();
_metalTexture = null;
}
}
Case 2:
class SomeClass
{
public void CreateTexture()
{
var metalTexture = device.CreateTexture(textureDescriptor);
metalTexture.Dispose();
}
}
Above you can see two simplified cases, which are demonstrates the issue.
The problem is in case 1. A texture's memory doesn't release after Dispose() call, when a created texture is stored in a class field. At the same time there is no problem, when texture's reference is stored in local variable.
Can anybody explain what is going on, and how to release texture's memory?
P.S.
It's not a reference count problem (there are no any other references to texture).