Results 1 to 5 of 5

Thread: Out of memory error

  1. #1
    KaneII
    Guest

    Angry Out of memory error

    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!

  2. #2
    Addicted Member
    Join Date
    Apr 2000
    Location
    England
    Posts
    246
    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
    Some Days, i just get this feeling that i'm helping to write dozens of Viruses...

  3. #3
    KaneII
    Guest
    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?

  4. #4
    Addicted Member
    Join Date
    Apr 2000
    Location
    England
    Posts
    246
    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
    Some Days, i just get this feeling that i'm helping to write dozens of Viruses...

  5. #5
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    To make everything clean you should release the memory used by arrays:

    Code:
    'Declares
    Dim Data() As YourType
    
    'Run program
    ReDim Data(10000)
    'Stuff here
    
    'Exit program
    Erase Data
    
    
    
    'Code improved by vBulletin Tool 2.0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width