Freeing DX resources in C#

Started by
4 comments, last by dacris 21 years, 8 months ago
How do I do it?? I use, for example: myTexture = null; But I don't think that that frees it. The VB interfaces have no Release() function, so how do I make sure that my textures have been released? I call GC.Collect(); but it does nothing. How on earth do I get rid of my Direct3D resources in C#? For example, I have a texture that I created to be used as a render target (D3DPOOL_DEFAULT) and I want to free it explicitly when the device needs to be reset. Unfortunately, by using the above methods, it doesn't get freed. Thus, the device reset call fails. Should I create a DirectX C++ wrapper while I still can? [edited by - dacris on July 17, 2002 4:17:32 PM]
Advertisement
I''ve recently looked through some VB samples and they don''t seem to free up their resources. So how do I prevent a memory leak? Does DX take care of it for me?
In the DX9 SDK (the managed wrapper), I''ve found methods such as Dispose() for textures. How would those have been implemented? Is it possible that they correspond to the C++ Release() functions?

I have the DirectX 9 SDK beta, but I don''t want to move to it yet, since the users of my program would have to install the DX9 runtime beta. Is there a way to use the managed wrapper with DX8?
Never mind, figured out a solution to my own problem.

For anyone interested, here it is:
You have to call
System.Runtime.InteropServices.Marshal.GetComInterfaceForObject
and then
System.Runtime.InteropServices.Marshal.Release
for the object retrieved in the previous call. This has to be done for all the interfaces that you wish to be released manually.

Here's a sample:
IntPtr p = System.Runtime.InteropServices.Marshal.GetComInterfaceForObject(myTexture, typeof(DxVBLibA.Direct3DTexture8));
System.Runtime.InteropServices.Marshal.Release(p);


Now my engine is working beautifully, without a single bit of C++ in it

[edited by - dacris on July 17, 2002 7:34:28 PM]
DirectX9 takes care of this.. I know because I recently installed the DX9 beta SDK. Each DX9 object has a Dispose() method which acts like the Release() method in C++.
Now, just as a note - would you guys having the DirectX 9 SDK please HONOUR YOUR NON DISCLOSURE AGREEMENT?


Regards

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)
RegardsThomas TomiczekTHONA Consulting Ltd.(Microsoft MVP C#/.NET)

This topic is closed to new replies.

Advertisement