   [.net] garbage collection and MDX
  Hi,i started to developing a game in C# with MDX 1.1.When i run this code the GC frees the memory as i aspected:class Program{    static void Main()    {   for (int i = 0; i < 5000; i++)   {  Bitmap bitmap = new Bitmap(256, 256);   }    }}But when i run this code no memory is freed:class Program{    static void Main()    {   PresentParameters presentParameters = new PresentParameters();   presentParameters.SwapEffect = SwapEffect.Discard;   presentParameters.Windowed = true;   Device device = new Device(0, DeviceType.Hardware, new Form(),  CreateFlags.HardwareVertexProcessing, presentParameters);   for (int i = 0; i < 1700; i++)   {  Texture texture = new Texture(device, 256, 256, 1, Usage.None, Format.A8R8G8B8, Pool.Managed);   }    }}I was developing in C++ for a few years, so i know, that the Direct3D Deviceholds a reference to the Texture. But i thought that when no references are hold by the user, like in my sample above, the GC should free the Textures.Now my question: Have i always use Texture.Dispose() to free the textures in my program or am i doing anything wrong?Thanks in advance.   
  This is a known “problem“ with MDX. The reason why your memory is not freed is that a Direct3D device holds a reference for every resource that you create for it. As long as you hold a reference for the device your textures will stay in memory too. Because of this you should call Dispose for every MDX object. Additional every managed object holds a reference to the unmanaged Direct3D object. A dispose will free this memory too if you don’t call dispose you have to wait for the GC and this can take a long time.;  The reason the device holds a reference is so that it can call events for device lost etc on each object. If you can live without this behaviour then turn it off and then textures will behave just like bitmaps.See Tom's blog on events and disposeWhilst this should solve the never being released problem is still a very good idea to call dispose when you are done as demirug suggested becuase objects that impement IDispose take 2 GCs to tidy up becuase they rely on finalizers. This applies to bitmaps too.;Quote:Original post by thezbuffer...Hey, that was really helpful.