Free memory in compact frame work 1.0
Hi all,
I'm writting a Point of Sales application for use on a PDA device, when I move from one screen to the next I use the me.Close() to close the previous screen(form) and then load the next screen. This is working fine, however when I go can check the running programs on the PDA device, it displays a list of all the forms I've entered, even the ones I've closed. This slowly slowly eats away at the available memory I have free on the PDA.
By using the me.Close() shouldn't all closed forms be removed and memory released?
Whats the work around for this?
Thanks
Coss
[590 byte] By [
Coss] at [2007-12-16]
Thanks but thats not really helping me.
Setting the form's caption to blank just hides the program from the "Running Programs" screen (on the PDA), however its not releasing the memory. Its the memory that I'm interested in. I would like to realese it when the each form is closed.
Cheers
Coss, did you actually read both entries that I pointed to?Go back and read number 3. It tells you about minimizebox set to false. If you are still having troubles, post a complete sample that we can run here and provide specific advice on.
Cheers
Daniel
Hi Daniel,
I do have the MinimizeBox = false, also I have the ControlBox = false and FormBorderStyle = none.
I don't see any links to attached a sample application, so below is a simplified version of what I'm doing.
Create new application with 3 forms have form1 as startup, also add a module
In the module add:
Friend frm2 As Form2
Friend frm3 As Form3
On form1 add two buttons, one to close form and the other to load form2, ie:
Private
Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frm2 = New Form2
frm2.ShowDialog()
End SubOn form2 add two buttons, one to close the form and other to load fom3, ie:
Private
Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
frm3 = New Form3
frm3.ShowDialog()
Me.Close() 'closes form2
End SubOn form3 add one button to close the form and add the closed event to load form2, ie:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private
Sub Form3_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
If Not frm2 Is Nothing Then
frm2 = Nothing
End If
frm2 =
New Form2
frm2.ShowDialog()
End SubStart the application load form2, then form3 then close form3 (to go back to form2) then load form3 and close again. Do this a few times then go to the running programs on the PDA and you'll see a list of form2 and form3 in the list. If you monitor the available memory you'll notice that it slowly diminishes.When you finally close the application notice the title of the open form. It quickly flips between the forms which are displayed on the PDA running programs then exits.
So my problem is, why don't the forms close when you execute the me.close()?
Remove these :
- Me.Close() inside Button2_Click(...)
- Complete Form3_Closed(...) sub
and everything will be fine !
This still doesn't work.
Lets start from the beginning. All the forms in the application have the ControlBox = False, FormBorderStyle = none and MinimiseBox = False. There are lets say 3 forms in the application. Each form has a button 'Close' to close the form and another button 'Next Form' to load the next form.
Now when the application starts, the first form is loaded (form1). Now when the 'Next Form' button is pressed, how would someone load the second form (form2) and close the first (form1). Then from form2 load the third form (form3) and close form2. When form3 is closed, load form2 and then when form2 is closed load form1.
Keep in mind, when closing of a form and loading of another the memory allocated for the closed form should be released. ie the memory available on starting the application and the memory left after form2 is closed to load form1 again should be the same. I know the GC should kick in after same time are release the memory but this doesn't seem to happen.
Cheers
Hi! To be honest, I don't think that your application design is very practical. However, I reckon your problem is the following:
When you close form3 the closing or closed event calls the Form3_Closed method. In that code you set frm2 to null, but you are NOT closing the form. Instead you are just removing the reference and end up with an orphaned form (memory occupied by a form gets only garbage collected when the form has been closed!).
Then you create a new form2 (hence the many form2 forms) and call the ShowDialog() method which blocks execution of all following statements in form3 and that is probably why form3 does not close as well (hence the many form3 forms).
So, try to use the Show() method instead of ShowDialog() and close form2 explicitly (or think of a better design where forms are hidden but not closed - also speeds up form display)..
kolya
Hi Kolya,
Thanks that works nice.