Jump to content
  • Advertisement

Archived

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

ArdeII

DirectX 9 mystical memory leak?

This topic is 5490 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

I have this very very simpe DirectX9 application which basically does nothing but opens window and cleares it (no 3D stuff is rendered). My problem is when the program is started it immediatelly starts to allocate memory and do not free it. When started the memory usage is 13,000k in Win task manager and it grows linearilly. I have noticed that DX tutorials does this same thing, but the samples which uses the GraphicsSample framework doesnt. I have also noticed that the memory is allocated within the render method (see code below) I use C# and SharpDevelop and Win2000. Please someone help me because I want to know what I''m doing wrong (or am I?). Have anyone suffered from same kind of problems? Thanks in advance. CODE ------ using System; using System.Drawing; using System.Windows.Forms; using Microsoft.DirectX; using Microsoft.DirectX.Direct3D; namespace Test { public class MemTest : Form { static void Main() { MemTest app = new MemTest(); app.Show(); while (app.Created) { app.Render(); Application.DoEvents(); } } private Device device; public MemTest() { InitializeGraphics(); } protected bool InitializeGraphics() { PresentParameters pres = new PresentParameters(); pres.Windowed = true; pres.SwapEffect = SwapEffect.Discard; device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, pres); device.RenderState.Lighting = true; return true; } protected void Render() { device.Clear(ClearFlags.Target, Color.Bisque, 1.0F, 0); device.BeginScene(); device.EndScene(); device.Present(); } } }

Share this post


Link to post
Share on other sites
Advertisement
I never used C# before, but if I was going to debug this I''d put a breakpoint on all 3 lines which have "new" in them... Run the program, it should only hit those 3 lines once while its initializing. If it keeps hitting them over and over, something is wrong. Try it.

Share this post


Link to post
Share on other sites
I was writing this
-----------------
Thanks for the advice,
the method where the news are is called only once.
If I comment the Render method out it still allocates memory that is in the application loop the application does absolutely nothing but loops and calls Application.DoEvents();
------------------

when I discovered that the method Application.DoEvents(); is to be blamed for memory allocation.

Why is that? Does anyone know?

-----

Share this post


Link to post
Share on other sites
The issue probably isn''t with DX or you, it''s probably the managed framework, but it''s probably not a problem. See, the garbage collector determines when the best time to collect excess memory is, depending on a variety of factors. This means that the memory usage as shown in task manager is not accurate. For a more accurate picture of how much memory your app is actually using, minimize it. This usually causes the garbage collector to run and thus the correct memory usage is shown.



Gamedev for learning.
libGDN for putting it all together.
An opensource, cross platform, cross API game development library.

Share this post


Link to post
Share on other sites
Thanks dude it works, but
it still bothers me that the memory usage is raising continuously. Doesnt this mean that if someone uses my application for long time period he runs out of memory?

-----

Share this post


Link to post
Share on other sites
No, it won''t. The garbage collector determines best time to run collection, which usually means when CPU usage is low, available memory is low, or a variety of other factors. It is generally very good at determining when to collect. For more information, check here:

Microsoft Information
More Microsoft Information




Gamedev for learning.
libGDN for putting it all together.
An opensource, cross platform, cross API game development library.

Share this post


Link to post
Share on other sites
Conclusion: I believe now

That Garbage Collection thing is so amazing thing that it is hard to believe that it works. I read this article and it convinced me to believe that it really does work!

http://www.doitin.net/memusage.htm

Note: When I was programming with C++ it was really annoying when you were reqiured to deallocate every memory allocation and work with those stinky pointers. Now with C# I wish that I could control the memory even a little and I really miss those real pointers. Funny isnt it

Share this post


Link to post
Share on other sites
C# does have pointers, you can access them by using the unsafe keyword. However, this is probably not recommended since you''re bypassing one of the main tenents of the framework. I''m also not sure how that would bode in some instances for the cross-language compatibility. Thanks for the article, a good insight.



Gamedev for learning.
libGDN for putting it all together.
An opensource, cross platform, cross API game development library.

Share this post


Link to post
Share on other sites
Yes I know that C# has pointers but they are so impracticable. Maybe I have understood wrong but if I want to use pointers like in C++ it is not possible because the memory is constantly being modified.

Example:

Node[] n;

public unsafe void ChangeNodesAddress(Node otherNode[])
{
fixed(Node* temp=&otherNode[12])
{
n=temp;
}
}

You cannot do this!!!

Or if you can do this(how?) you have no guarantees that the address points to the right place after a while.

Am I right or wrong?
I have read some pointer articles but I havent found any usefull yet, so some tips would be appreciated

Share this post


Link to post
Share on other sites
Honestly, I don''t know.



Gamedev for learning.
libGDN for putting it all together.
An opensource, cross platform, cross API game development library.

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!