PC Review


Reply
Thread Tools Rate Thread

Direct3D FromStream + MemoryStream= memory leak?

 
 
Big D
Guest
Posts: n/a
 
      27th Sep 2005
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!
 
Reply With Quote
 
 
 
 
Dave
Guest
Posts: n/a
 
      27th Sep 2005
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?

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Big D" <(E-Mail Removed)> wrote in message news:Xns96DE62975BF84supagoatatverizonDne@216.196.97.142...
> 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!



 
Reply With Quote
 
Big D
Guest
Posts: n/a
 
      3rd Oct 2005
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.

"Dave" <NOSPAM-(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> 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?
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make MODI.Document not leak memory? I have millions of images to OCR but each time i OCR one it leaks memory. How to do the OCR and then clean up so that my app doesnt leak memory? DR Microsoft C# .NET 2 5th Feb 2008 02:52 AM
How to make MODI.Document not leak memory? I have millions of images to OCR but each time i OCR one it leaks memory. How to do the OCR and then clean up so that my app doesnt leak memory? DR Microsoft Dot NET 1 4th Feb 2008 11:43 PM
How to make MODI.Document not leak memory? I have millions of images to OCR but each time i OCR one it leaks memory. How to do the OCR and then clean up so that my app doesnt leak memory? DR Microsoft Dot NET Framework 1 4th Feb 2008 11:41 PM
Getting pointer to the memory of MemoryStream Maciej Oszutowski Microsoft Dot NET 7 23rd Sep 2007 12:00 AM
MemoryStream Memory Intensive? newbie Jim Bayers Microsoft Dot NET 6 23rd Jul 2004 11:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:08 AM.