Direct3D FromStream + MemoryStream= memory leak?

B

Big D

I'm trying to write a game in c# using managed direct3d, and I have a bit
of a situation. I'm using sprites to draw my 2d graphics, and I'm
generating some of my sprites dynamically by writing to Bitmaps, then
saving the Bitmaps to a MemoryStream that I load as a texture using
Device.FromStream.

My problem is that using this method seems to cause a memory leak over
repeated calls to FromStream. It looks to me like when I call FromStream,
Direct3D keeps a reference to my stream so it doesn't get GC'd.

I've tried re-using the same MemoryStream and setting the Position to 0
each time, and I've tried using a new MemoryStream each time.

I'm using a somewhat old version of DX9, so maybe (hopefully?) it's fixed
now, but I wanted to know if anyone could give any advice or tell me if
this was a known issue.

Thanks!
 
D

Dave

Dispose of each object when your done using it. This is what the ability to explicitly release managed resources is for.

stream.Dispose();

If you are already disposing of the objects, does disposing the device, or whatever has the reference to your stream, actually free
up the memory while the application is still running?
 
B

Big D

I did some more digging and discovered that it was a directx9 bug. I
updated my dx runtime and the problem was fixed!

I should, as someone else mentioned in a workaround, learn to draw directly
to textures instead of drawing on bitmaps then converting them to textures.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top