Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42225

How long does a form stay in memory when it is closed?

$
0
0
I have 3 questions about this!

1. This is my main form. Editor2 is another form that is part of the project. When the main form is shown, there is 1 button that you can click on to show the Editor2 form.
Code:

Public Class Test_1
    Dim test As New Editor2

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        test.ShowDialog()
    End Sub
End Class

Here is the Editor2 form code.
Code:

Public Class Editor2
    Public counter As Integer = 0

    Private Sub Editor2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        counter += 1

        Label1.Text = counter.ToString
    End Sub
End Class

As you can see, I place a counter to test opening and closing the form. Everytime I click the 'x' to close the form, I can launch it again by clicking on the button and it will show with a label incremented + 1. Opening and closing so far, never lost the count.

I was looking up information on object lifetimes and I got a little confused about what is happening under the hood.
My first question is this: Will all the member variables of the Editor2 form stay in memory, or is this unsafe. Can the object at anytime be destroyed automatically, losing member data? This will be an editor of sorts, and the user will probably have edited data in it and possibly not saved, when temporarily closing the Editor2 form.

2. Since I am not creating the form programmatically, but instantiating it after it is added to the project from the VB. Net IDE, amd I placing the creation of the form in the right place in the main form above?

3. My second question is a comparison to MDI applications. Later I might move to an MDI application instead, and I would like to know what the safest way is to make data persistent, so it is not accidentally lost before the user saves it.

Viewing all articles
Browse latest Browse all 42225

Trending Articles