Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
It's wierd, whenever I try to close my window (that's 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 it's doing this?
  • *Experts*
Posted

Is there a game loop you are inside?

 

For example:

'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.

  • *Experts*
Posted

Could you post the project so we can take a look?

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • 2 weeks later...
Posted

i had this problem too. make sure you call dispose on everything...esp the vb/ib's. it should fix things right up.

 

(i bet you're making new vb's every frame huh?)

Posted

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 don't 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?

Posted

Object.Dispose destroys the object and marks it for collection

I'm 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

.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Posted (edited)

I asked Tom Miller about this today. He says it doesn't automatically get cleaned up by the garbage collector when it goes out of scope because when it's created, it gets hooked to it's device's 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 you've built up. It doesn't really hang, it just takes it's 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

Edited by Lance
Posted

= 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 wouldn't happen for 90 seconds

 

Object.Dispose

Exposed by IDisposable

Used for Class that holds references to unmanaged data (i.e. file handle). These references can't be freed by the Garbage Collector ; .NET doesn't 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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...