PDA

Click to See Complete Forum and Search --> : Out of memory error


KaneII
Jul 17th, 2001, 11:23 AM
two questions (which may be interlinked):

1)
I often get 'out of memory' errors while running a game, which I'm making. It uses quite a lot of memory (about 10 MB), but even then I have 100s of MB of free disk space for virtual memory.
Also, the largest variables are declared as public in a module so if I'm not mistaken, they should be allocated from the heap, not from the stack, so it can't be that the program runs out of stack space.

What could be causing this error?

2)
The program uses a lot of device contexts. Are device contexts allocated from video memory?
Could VB be referring to video memory when it gives the out of memory error?

Any suggestions are more than welcome!

Nirces
Jul 18th, 2001, 05:17 AM
VB creates DC in memory, DirectX will try to create surfaces in Video Memory if possible otherwise Normal Memory.

Chances are your not deleting your bitmaps before you release your DC's (and therefore do not release them)

Have a Look at this thread for a Discussion about it and a soultion:
Link (http://forums.vb-world.net/showthread.php?s=&threadid=88028)

KaneII
Jul 18th, 2001, 08:55 AM
this is the method I use for loading/unloading DC's:

---------------
dim DC as long, Original as long

'to load
createcompatibledc(someform.hdc)
Original=selectobject(DC, loadpicture(path))

'to unload
selectobject DC, Original
deletedc DC
deleteobject Original
---------------

this is the correct method, isn't it?

And besides I have 100s of MB of free virtual memory left anyway, so unloading a few DCs incorrectly wouldn't make a difference big enough to throw that error. Plus such a difference would show up in the System Monitor under allocated memory, which it doesn't.

Any other ideas?

Nirces
Jul 18th, 2001, 09:41 AM
this may of been a typo, your your unload function is wrong:

selectobject DC, Original
deletedc DC
deleteobject Original

the above method doesn't release the DC at all
it should be:

selectobject DC, Original
deleteobject Original
deletedc DC

try that

otherwise i'm not sure

Fox
Jul 18th, 2001, 10:30 AM
To make everything clean you should release the memory used by arrays:


'Declares
Dim Data() As YourType

'Run program
ReDim Data(10000)
'Stuff here

'Exit program
Erase Data



'Code improved by vBulletin Tool 2.0 (http://fox.acky.net/downloads/vbtool.zip)