Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

dacris

Freeing DX resources in C#

This topic is 5816 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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++.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!