473,487 Members | 2,461 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Direct3D FromStream + MemoryStream= memory leak?

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!
Nov 17 '05 #1
2 2688
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" <no****@toemail.com> wrote in message news:Xn**********************************@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!

Nov 17 '05 #2
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" <NO*********@dotcomdatasolutions.com> wrote in
news:Ok**************@TK2MSFTNGP10.phx.gbl:
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?


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4634
by: CanyonJ | last post by:
I've been running into a frustrating problem for a while now. I use image.FromStream to open a tif, then perform some drawstring methods, and then save the file again. The tiffs are in 1 bit per...
1
5130
by: halise irak via .NET 247 | last post by:
I get an "ArgumentException: Invalid parameter used at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement)" exception. it is too ridicilious to get such an...
8
3389
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? ...
4
11726
by: Detlef Huettenbach | last post by:
I was trying to convert a Windows Forms prototype application to an ASP.NET solution that makes use of loading data streams into the Image Web/Windows control. For WinForms no problem. However in...
1
8090
by: Mchuck | last post by:
I've seen several newsgroup topics everywhere concerning this, as well as a couple of articles from the MSDN website, but this error still baffles me. It has to do with using the...
9
8748
by: Tom John | last post by:
Hi I am storing images in an access database, based on an MSDN article. The code i use to store is as follows: <code> 'Create the command object Dim command As New...
7
4775
by: bookon | last post by:
I was running into the System.Drawing.Image.FromStream "parameter is not valid" on some of the images I was retrieving from a blob column in Sql Server. I thought there were corrupt images as...
3
5516
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hi, I am using dotnet remoting with a binarry formatter. I have a property that returns a memorystream that has had a file loaded into it. When I try to access this property though I get an...
0
1606
by: walve_wei | last post by:
<1>use the D3D control panel, enable the debug DLL and maximum validation,for D3D control panel ,you need to install the directx sdk. <2>Start up the debug monitor (<MSVC install...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7352
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5445
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
618
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
272
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.