Image of Navigational Panel mapped to Contents / Home / Search unload/show Code
Tech Support Question

Image of Line Break

Q. I am programming a Hangman game. I only have three forms: the game screen, and win/loose form. I go to play the game, then win/lose form, then back to game, and so on.

This continues over and over. After about 4 games, I get "Out of Memory" and the system crashes trying to load one of the bmp's.

Thank you for your time. The Hangman game is a project for school, at Southwest Texas State University in San Marcos, Texas.

From: Robert J. Rimes II
Email: rr07424@swt.edu

A. Robert, I can't be 100% certain about what your problem is without actually looking at the code. However, I recognise the symptoms of a classic problem here which I think is what your problem is. What may be happening is that your forms are staying in memory and additional copies keep getting loaded. Because you are using a few bitmaps this chews through your memory fairly quickly.

Why is this happening? Typically it's because you have some code like this, where you are going from your game form to your win/lose form and back.

  Unload Me
  frmWinLose.Show MODAL

The problem with that is this: when you go back to the form in question you load it because you know that you unloaded it (as above) and you show it. Unfortunately you never actually unloaded it, because the code above never finishes executing. Why? Because the unload command is actually cued until all the code in that form has been processed, which means it won't actually unload until after that Show modal statement. Unfortunately because that show is Modal that statement will not return until the following form is unloaded. By that time the following form has loaded the first form again, and we are well on the way to running out of memory.

Basically what you need is a smoother way to transition between forms, your first step is to not use MODAL forms (which I have assumed you are using). That should allow unload calls like the above to finish executing. You might be interested to have a look at the article: Handling Chained Modal Dialogs in VB. The article includes some useful (and simple) code for transitioning between forms.

I hope this helps you out, your situation may be different to what I've described but I think the central problem is still that you end up with too many forms in memory. So have a close look at your unload/show code.


Image of Arrow to Previous Article Image of Arrow to Next Article

[TECH SUPPORT TOC]
Image of Line Break
[HOME] [TABLE OF CONTENTS] [SEARCH]