Jump to content
  • Advertisement
Sign in to follow this  
MePHyst0

[.net] [VB.NET] DirectX Control and memory leaks

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

Hi, I started working on a small DirectX UserControl with Vb.NET. So I made a simple skeleton of the control, then I tested it with a simple render loop cleaning the UserControl area to Blue. That went fine, however I've noticed that the process keeps allocating more and more memory(aproximately 30 kB/s). Have anybody any idea what can cause these memory leaks? Thanks in advance P.S.: I've just tried the CreateDevice tutorial from October SDK and it's leaking the memory too. Can the bug be in my workstation?

Share this post


Link to post
Share on other sites
Advertisement
Hi

I had a memory leak problem before, put your debug runtime on max validation and full verbosity. Some kind soul then told me to search for DebugView to see the debug output, very neat tool.

Here is my cited thread.

Argh further maths exam (AS D1 module) at 1...wish me luck! I _can_ get 100% but it takes 2hrs rather than 1hr30 :( I'm slow and stupid :(

Bonne chance

Share this post


Link to post
Share on other sites
Hi,

Thanks for your reply. I've alredy checked the debug output(everything set to maximum) with no success. It says that there's nothing wrong.

I'm totally lost, I've tweaked everything and the leaks were always there. Please, If anyone could give me any hint/advice, I would appreciate it a lot. Thanks a lot.

Share this post


Link to post
Share on other sites
How are you doing your render loop? A code sample would be useful. Just telling us that "memory keeps getting allocated" isn't particularily helpful since we have no idea what your code is doing.

Share this post


Link to post
Share on other sites
Agreeing with Washu (duh! ;)) - it might not even mean you have a memory leak when you're dealing with garbage collectors - it probably does mean you should reconsider the alocations you're doing, since you probably will end up with the garbage collector kicking in at innoportune times and causing random slowdowns.

Basically, remember that the Vb.net garbage collector works different from the vb6 one.

Share this post


Link to post
Share on other sites
If debug output shows nothing (does not spew out lots of stack traces for unfreed memory), probably saying 'Mem fini!' at the end, then it's probably not DirectX's fault.

Like others said, it's probably the normal operation of the garbage collector.
I believe the CreateDevice tutorial uses Application.DoEvents...not a good thing:
Quote:
Rick's blog
The first loop I used was the old standby loop:


while (Created)
{
Frame();
Application.DoEvents();
}


Sadly, this loop is mortifyingly bad about allocations. To give you an example, if you do nothing else in a frame, this kind of loop can generate over 50MB of garbage in 100000 frames. Under CLR profiler, you’ll see a shark tooth pattern of allocation and collection emerge in the timeline. Lots of collections == bad long-term performance.


Check out Rick's and Tom's blogs. (and this is Tom's post on the render loop)

Hope that helps

Share this post


Link to post
Share on other sites
Thanks a lot guys. The link to those blogs were quite helpful, the memory allocation decresed dramatically, however there's still some ignoreable overhead.
Anyways, I'm having some problems with those game loops. I've tried to implement this game loop, however it's seems that my form is not recieving any message. Here's my implementation:


Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (ByVal lpMsg As Message, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long


Private Sub OnApplicationIdle(ByVal sender As System.Object, ByVal e As System.EventArgs)

Do While AppStillIdle()

UserControl11.Render()

Loop
End Sub
Private Function AppStillIdle() As Boolean

Dim msg As Message

Return (Not PeekMessage(msg, 0, 0, 0, 0))

End Function
Private Sub StartMainLoop()
AddHandler System.Windows.Forms.Application.Idle, AddressOf OnApplicationIdle
End Sub





Do you see any mistakes in my code?


[Edited by - MePHyst0 on January 25, 2006 3:07:58 PM]

Share this post


Link to post
Share on other sites
For starters, and it may be from just pasting a fragment of your code, where are you calling StartMainLoop() to attach to the Idle event? Just want to get that out of the way first.

Also, are you calling Application.Run()? I'm assuming you are, but there are alternative ways to doing this that you may be trying which could be causing issues.

~Graham

Share this post


Link to post
Share on other sites
Hi,
Thanks for your reply. Here's the missing code:


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

StartMainLoop()

End Sub


Shared Sub Main()
Application.Run(New Form1)
End Sub



Sub Main is the entry point of my application.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!