Object = nothing but still exists???

G

Guest

I have a windows class form2 that contains a datagrid. With Cor's help I am
using this strategy to better manage memory.

In form one I have:

dim Matrix_A as form2

Private Sub populateA()
Dim Matrix_A As New form2
Method to fill grid and display form
end sub

Later, after the first execution of populateA I want to be able to hide the
shown form and reexecute populateA with new information. However, after
executing the first populateA completes Matrix_A is nothing.

Since it is nothing, how can I make it dissappear so I won't have two
(confusing) Matrix_A forms displayed? And, if it is nothing, how come I can
browse its datagrid?
 
G

Guest

mark said:
I have a windows class form2 that contains a datagrid. With Cor's help I am
using this strategy to better manage memory.

In form one I have:

dim Matrix_A as form2

Private Sub populateA()
Dim Matrix_A As New form2
Method to fill grid and display form
end sub

Later, after the first execution of populateA I want to be able to hide the
shown form and reexecute populateA with new information. However, after
executing the first populateA completes Matrix_A is nothing.

Since it is nothing, how can I make it dissappear so I won't have two
(confusing) Matrix_A forms displayed? And, if it is nothing, how come I can
browse its datagrid?

This is bad programming. You are declaring Matrix_A variable twice.

I think you wanted to do:

dim Matrix_A as form2
Private Sub populateA()
Matrix_A = New form2
Matrix_A.showdialog
Method to fill grid and display form
end sub
 
G

Guest

Your method is better, But I still get multiple visible copies of Matrix_A if
I execute populateA multiple times.. I know I am being dunderheaded but I
just can't figure out how to close the originals when a new Matrix_A comes
into existance (other than clicking the close control).
 
G

Guest

mark said:
Your method is better, But I still get multiple visible copies of Matrix_A if
I execute populateA multiple times.. I know I am being dunderheaded but I
just can't figure out how to close the originals when a new Matrix_A comes
into existance (other than clicking the close control).

How do you know how to close Matrix_A? What is suppose to trigger
closing it? You may be looking for:


dim Matrix_A as new form2
Private Sub populateA()
Matrix_A.Show
Do a bunch of stuff
Matrix_A.Close
end sub
 
T

tomb

Or:
How do you know how to close Matrix_A? What is suppose to trigger
closing it? You may be looking for:
Maybe this modification is what you're looking for:
dim Matrix_A as new form2
Private Sub populateA()

if Matrix_A is nothing then Matrix_A = new form2
Matrix_A.Show
Do a bunch of stuff

end sub


Tom
 
C

Cor Ligthert [MVP]

Mark,
I have a windows class form2 that contains a datagrid. With Cor's help I am
using this strategy to better manage memory.

I don't see where I gave you this advice. I forever try to avoid setting
things global, therefore I am curious where I wrote this to you.

It can be that you destilated this from something I wrote because you
insisted on doing things like this, now it looks as if I would have done
this. I certainly don't call this good memory management, because form2 will
only be garbaged at the end of the program.

Can you show me where I wrote this?

Cor
 
C

Cor Ligthert [MVP]

Mark,

Found it, I assume that you understood it different than I intended.

This is what I wrote yesterday
------------------------------------------------------------------------------------------------
The normal way for this is declaring your form not gobaly
Private myForm as Form2

However forever in the procedure

dim myForm as New Form2
myForm.Show
And to see if it is still alive before that

if myForm.IsDisposed = false
-----------------------------------------

I assume seeing your message now that you understood from this

*However always in the procedure has to be*
While I intended to tell
*However instead of that forever in the procedure*

Please as forever keep your follow ups inside the original threads if they
are younger than some days, this gives only confusions.

Cor
 
O

Oenone

tomb said:
Or:
if Matrix_A is nothing then Matrix_A = new form2

Or:

\\\
If Not Matrix_A Is Nothing Then
Matrix_A.Close()
End If
Matrix_A = New Form2
///

This will close any existing form prior to the new one opening.
 
G

Guest

Maybe this modification is what you're looking for:


if Matrix_A is nothing then Matrix_A = new form2

WORKS although I'm using:

dim Matrix_A as form2
Private Sub populateA()What's the difference?

mark
 
M

m.posseth

if you only need the object pointer inside the method then it doesn`t make
sense to declare it in global scope ( global for the class in this case )

creating it in the method has the big benefit that the object is created on
the stack and thus is faster and will be inmediatly cleaned up as soon as
the method has finished executing

regards

Michel Posseth [MCP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top