Hi,

i'm developing an application for pocket pc.
In this application I have a number of screens that I build dynamically according to database records.
I have the following code:

VB Code:
  1. ' Global
  2.     ' Controls for screen A
  3.     Private ar_pcbThemaButtons() As PictureBox
  4.  
  5.  
  6.     ' Controls for screen B
  7.     Private ar_pnlSubThemaButtons() As Panel
  8.     Private ar_pcbSubThemaButtons() As PictureBox
  9.     Private ar_lblSubThemaButtons() As Label
  10.  
  11.  
  12.     ' Controls for Screen C
  13.     Private ar_pnlObjektenButtons() As Panel
  14.     Private ar_pcbObjektenButtons() As PictureBox
  15.     Private ar_lblObjektenButtons() As Label
  16.  
  17.  
  18.     Private sub getScreenA()
  19.             ClearPreviousScreen()
  20.             ...
  21.             ar_data = getFromDB()
  22.  
  23.  
  24.             Dim i as integer
  25.             redim ar_pcbThemaButtons(ar_data.length - 1)
  26.             For i = 0 to ar_data.length - 1
  27.                    ar_pcbThemaButtons(i) = new PictureBox
  28.                    ' Set Props for ThemaButton (Image, size, location)
  29.                    .....
  30.                    pnlButtonHolder.Controls.add(ar_pcbThemaButtons(i)
  31.             Next
  32.     End Sub

For screen B and C is that the same thing except that I use a
panel, picturebox and label for them.
Now between switching the screens I do a ClearPreviousScreen().

VB Code:
  1. Private sub ClearPreviousScreen()
  2.              Dim oCtrl as Control
  3.              For each oCtrl in me.controls ' This is the place where it
  4. goes wrong
  5.                     oCtrl.visible = false
  6.              next
  7.  
  8.  
  9.              dim i as integer
  10.              if ScreenA then
  11.                    for i = 0 to ar_pcbThemaButtons.length - 1
  12.                           if not ar_pcbThemaButtons(i) is nothing then
  13.                                   ar_pcbThemaButtons(i).dispose()    'Remove the control
  14.                           end if
  15.                    next
  16.              end if
  17.      End Sub
So in the ClearPreviousScreen I dispose of the controls that I don't
need anymore.
This works for a while until the app exists without an error message. (At the point where I
start my loop through the me.Controls collection. )
Is my way of working incorrect?????
I can't seem to figure out what I'm doing wrong.

If I don't use the dispose on the array of controls the application doesn't exit.
But this results after a while in an out of memory error.

Could somebody help me out here?

Regards,

Steve