Program halts when unload DX

RazerWriter

Active member
Joined
Jun 26, 2003
Messages
32
Its wierd, whenever I try to close my window (thats running on dx9), the windows closes, but the program is still in run mode, then when I try to end it manually, it freezes for a long time and then closes. Can anyone tell why its doing this?
 
Is there a game loop you are inside?

For example:
Code:
declare bContinue form-wide
Do Until bContinue
  rendering code and game code here
Loop
If you try to close the game without ending the loop, it will still be in run mode. You need to make sure you set bContinue = True to close the program.
 
I have an array of vertices. The program only does this when I load up the vertices and create them. Strange, the memory count nearly quadruples after I load them.
 
You can attach the project to posts by using the attachment box on the New Reply screen.
 
Yes VolteFace, I know how this forum works, thank you. I just dont want the code to get into the wrong hands if you know what I mean.
 
i had this problem too. make sure you call dispose on everything...esp the vb/ibs. it should fix things right up.

(i bet youre making new vbs every frame huh?)
 
Problem solved

I got it to work.. what I did was load and create all the objects before I load anything else (like the form). Then, only dispose them at the end of the program. This way, I dont have to initialize and destroy objects constantly. The only thing that I load and unload during the program are the textures to free memory, everything else gets initialized right away.

Another question...

Should I use this method:
Object.Dispose
Object = nothing

are they the same?
 
Object.Dispose destroys the object and marks it for collection
Im not exactly sure what Object = Nothing does, but I think it just pushes the object out without Disposing so its only marked for collection when it goes out of scope

You should just use .Dispose
 
I asked Tom Miller about this today. He says it doesnt automatically get cleaned up by the garbage collector when it goes out of scope because when its created, it gets hooked to its devices disposing event. So when it goes out of scope, the GC still counts a reference to it. What you see when you exit your program is your device cleaning up all those resources that youve built up. It doesnt really hang, it just takes its time.

Fortunately, the summer beta added a toggle to tell the device to use weak references instead. Also new to the summer beta are resources that actually implement IDispose, so you have put them in using blocks now. (yay!)

Lance
 
Last edited by a moderator:
= Nothing
Happens when a variable goes out of scope
Used for quicker Garbage Collecting and for program logic to check

e.g. you write a Division function because you do not want it to throw division by 0 errors. Instead, return Nothing, indicating the value is indeterminate
-or-
use obj=Nothing to free up memory for long running functions. If func() loads ten large bitmaps, gets data from them, then starts a recursive algorithm on the data that takes 90 seconds, you can set those bitmaps to Nothing to free up memory, which otherwise wouldnt happen for 90 seconds

Object.Dispose
Exposed by IDisposable
Used for Class that holds references to unmanaged data (i.e. file handle). These references cant be freed by the Garbage Collector ; .NET doesnt knows about them. When the Object is freed, the data remains referenced and will stay. You can no longer access your Class instance (it is Nothing), so it is impossible to know where the data is to free it. This causes Leaks.
 
Back
Top