473,396 Members | 1,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

formArray close / dispose issue

I have created myself an issue, and perhaps my idea wasn't as bright as I
thought it was originally.
If someone can help me figure out what the correct train of thought should
be - or if there is a solution to this one.

I created a dummy mdi app.
In the main form ( frmMainScreen ) I created a variable as such:
<written in notepad to trim everything down>

Public Shared frmFormsOpen() As frmMyTestForm

Now, in a totally seperate sub form opend from the main form I do this on a
button click:

LengthOfGames = (frmMainScreen.frmFormsOpen.Length - 1)
ReDim Preserve frmMainScreen.frmFormsOpen(LengthOfGames)

frmMainScreen.frmFormsOpen(LengthOfGames) = New frmMyTestForm
frmMainScreen.frmFormsOpen(LengthOfGames).MdiParen t = Me.MdiParent
'Remember that this form is also an mdi child of the main form.
'Set my own property for later use
frmMainScreen.frmFormsOpen(LengthOfGames).GameID = anIntegerValue

frmMainScreen.frmFormsOpen(LengthOfGames).Show()

'Works Great
So in other code on other child forms forms I can do stuff like this:

For Each SearchForm As frmMyTestForm In
frmMainScreen.frmFormsOpen
If SearchForm.GameID = mytestID Then 'mytestID is set to a
value from something else
SearchForm.BringToFront()
Exit For
End If
Next
My problem is this:

where do i actually remove the array element when the form is closed. I do
not want it to stay in the array.
I do not think I can do it in the _FormClosed of the
frmMainScreen.frmFormsOpen(LengthOfGames)._FormClo sed
because I am actually in the form itself still - so I am assuming I cannot
kill the object when I am still using the object.
( im trying to kill myself from myself ).

That is my issue I have created myself and I was wondering if someone can
point me in the right direction on how to get around this issue.

Thanks,

Miro

Oct 29 '08 #1
10 1221
"Miro" <mi**@beero.comschrieb
where do i actually remove the array element when the form is
closed. I do not want it to stay in the array.
Do yourself a favor and use a List(Of frmMyTestForm) instead of the array.
(which VB version?) Safes you from item shifting and redimming.
I do not think I can do it in the _FormClosed of the
frmMainScreen.frmFormsOpen(LengthOfGames)._FormClo sed
because I am actually in the form itself still - so I am assuming I
cannot kill the object when I am still using the object.
( im trying to kill myself from myself ).
You don't kill anything by removing one reference. You can safely remove the
item from the list in the FormClosed event. The object on which the current
method is executed is never destroyed.
Armin

Oct 29 '08 #2
Its vb 2008

Thank you for the post.
I was under the impression - since I am 'sitting' in the object still during
_FormClose then I cannot Remove my object from underneith my feet.

Im assuming then by your statement
>The object on which the current method is executed is never destroyed.
That once I leave the form and it does close - it will be destroyed in the
background - I dont need to run anything else?

I will google and search up "List" to use a list instead of an array.

Thank you,

Miro

"Armin Zingler" <az*******@freenet.dewrote in message
news:ub**************@TK2MSFTNGP02.phx.gbl...
"Miro" <mi**@beero.comschrieb
>where do i actually remove the array element when the form is
closed. I do not want it to stay in the array.

Do yourself a favor and use a List(Of frmMyTestForm) instead of the array.
(which VB version?) Safes you from item shifting and redimming.
>I do not think I can do it in the _FormClosed of the
frmMainScreen.frmFormsOpen(LengthOfGames)._FormCl osed
because I am actually in the form itself still - so I am assuming I
cannot kill the object when I am still using the object.
( im trying to kill myself from myself ).

You don't kill anything by removing one reference. You can safely remove
the
item from the list in the FormClosed event. The object on which the
current method is executed is never destroyed.
Armin
Oct 29 '08 #3
"Miro" <mi**@beero.comschrieb
Im assuming then by your statement
>>The object on which the current method is executed is never destroyed.
That once I leave the form and it does close - it will be destroyed in the
background - I dont need to run anything else?
Yes, nothing else is required.
I will google and search up "List" to use a list instead of an array.
Not required to google - look in the object browser. It's
System.Collections.Generic.List(Of T)

see also:
http://msdn.microsoft.com/en-us/library/41107z8a.aspx
Armin

Oct 29 '08 #4
Miro,

You can find all the mdi forms by using
\\\
me.MDIParent.MDIChildren
///

http://msdn.microsoft.com/en-us/libr...ichildren.aspx

Probably much easier,

Cor
"Miro" <mi**@beero.comschreef in bericht
news:Os****************@TK2MSFTNGP03.phx.gbl...
>I have created myself an issue, and perhaps my idea wasn't as bright as I
thought it was originally.
If someone can help me figure out what the correct train of thought should
be - or if there is a solution to this one.

I created a dummy mdi app.
In the main form ( frmMainScreen ) I created a variable as such:
<written in notepad to trim everything down>

Public Shared frmFormsOpen() As frmMyTestForm

Now, in a totally seperate sub form opend from the main form I do this on
a button click:

LengthOfGames = (frmMainScreen.frmFormsOpen.Length - 1)
ReDim Preserve frmMainScreen.frmFormsOpen(LengthOfGames)

frmMainScreen.frmFormsOpen(LengthOfGames) = New frmMyTestForm
frmMainScreen.frmFormsOpen(LengthOfGames).MdiParen t = Me.MdiParent
'Remember that this form is also an mdi child of the main form.
'Set my own property for later use
frmMainScreen.frmFormsOpen(LengthOfGames).GameID = anIntegerValue

frmMainScreen.frmFormsOpen(LengthOfGames).Show()

'Works Great
So in other code on other child forms forms I can do stuff like this:

For Each SearchForm As frmMyTestForm In
frmMainScreen.frmFormsOpen
If SearchForm.GameID = mytestID Then 'mytestID is set to a
value from something else
SearchForm.BringToFront()
Exit For
End If
Next
My problem is this:

where do i actually remove the array element when the form is closed. I
do not want it to stay in the array.
I do not think I can do it in the _FormClosed of the
frmMainScreen.frmFormsOpen(LengthOfGames)._FormClo sed
because I am actually in the form itself still - so I am assuming I cannot
kill the object when I am still using the object.
( im trying to kill myself from myself ).

That is my issue I have created myself and I was wondering if someone can
point me in the right direction on how to get around this issue.

Thanks,

Miro

Oct 29 '08 #5
You are confusing removing a reference to an object from a list with
destruction of the object.

An object can have many references. Removing those references does
nothing other than, when all references have been removed, make the
object available for garbage collection. It does not cause the object
to be destroyed.

And as Armin said, please don't use arrays for this. List (Of T) is
much better.

On Tue, 28 Oct 2008 23:57:20 -0400, "Miro" <mi**@beero.comwrote:
>Its vb 2008

Thank you for the post.
I was under the impression - since I am 'sitting' in the object still during
_FormClose then I cannot Remove my object from underneith my feet.

Im assuming then by your statement
>>The object on which the current method is executed is never destroyed.
That once I leave the form and it does close - it will be destroyed in the
background - I dont need to run anything else?

I will google and search up "List" to use a list instead of an array.

Thank you,

Miro

"Armin Zingler" <az*******@freenet.dewrote in message
news:ub**************@TK2MSFTNGP02.phx.gbl...
>"Miro" <mi**@beero.comschrieb
>>where do i actually remove the array element when the form is
closed. I do not want it to stay in the array.

Do yourself a favor and use a List(Of frmMyTestForm) instead of the array.
(which VB version?) Safes you from item shifting and redimming.
>>I do not think I can do it in the _FormClosed of the
frmMainScreen.frmFormsOpen(LengthOfGames)._FormC losed
because I am actually in the form itself still - so I am assuming I
cannot kill the object when I am still using the object.
( im trying to kill myself from myself ).

You don't kill anything by removing one reference. You can safely remove
the
item from the list in the FormClosed event. The object on which the
current method is executed is never destroyed.
Armin
Oct 29 '08 #6
Thank you -
I have changed it to use the List(Of T) and it works great and 10x easier.

I used an array because of my old dos day programming - arrays is all we
had.

Miro

"Armin Zingler" <az*******@freenet.dewrote in message
news:ej**************@TK2MSFTNGP03.phx.gbl...
"Miro" <mi**@beero.comschrieb
>Im assuming then by your statement
>>>The object on which the current method is executed is never destroyed.
That once I leave the form and it does close - it will be destroyed in
the
background - I dont need to run anything else?

Yes, nothing else is required.
>I will google and search up "List" to use a list instead of an array.

Not required to google - look in the object browser. It's
System.Collections.Generic.List(Of T)

see also:
http://msdn.microsoft.com/en-us/library/41107z8a.aspx
Armin
Oct 30 '08 #7
I see,

I was the understanding that if i say
dim bla as new form1

then I was under the impression the object instantiated and the object
exists in bla which was dim'd here.

To 'remove' it from this 'dim' would be pulling the rug from under me.

As I understand your comment - the object "REFERENCE" is dim'd here, but the
actaul object exists somewhere else, so I can
"undim" my bla without worries. ( if undim was a word ) but basically
remove it from bla.

Miro

"Jack Jackson" <jj******@cinnovations.netwrote in message
news:sj********************************@4ax.com...
You are confusing removing a reference to an object from a list with
destruction of the object.

An object can have many references. Removing those references does
nothing other than, when all references have been removed, make the
object available for garbage collection. It does not cause the object
to be destroyed.

And as Armin said, please don't use arrays for this. List (Of T) is
much better.

On Tue, 28 Oct 2008 23:57:20 -0400, "Miro" <mi**@beero.comwrote:
>>Its vb 2008

Thank you for the post.
I was under the impression - since I am 'sitting' in the object still
during
_FormClose then I cannot Remove my object from underneith my feet.

Im assuming then by your statement
>>>The object on which the current method is executed is never destroyed.
That once I leave the form and it does close - it will be destroyed in the
background - I dont need to run anything else?

I will google and search up "List" to use a list instead of an array.

Thank you,

Miro

"Armin Zingler" <az*******@freenet.dewrote in message
news:ub**************@TK2MSFTNGP02.phx.gbl...
>>"Miro" <mi**@beero.comschrieb
where do i actually remove the array element when the form is
closed. I do not want it to stay in the array.

Do yourself a favor and use a List(Of frmMyTestForm) instead of the
array.
(which VB version?) Safes you from item shifting and redimming.

I do not think I can do it in the _FormClosed of the
frmMainScreen.frmFormsOpen(LengthOfGames)._Form Closed
because I am actually in the form itself still - so I am assuming I
cannot kill the object when I am still using the object.
( im trying to kill myself from myself ).

You don't kill anything by removing one reference. You can safely remove
the
item from the list in the FormClosed event. The object on which the
current method is executed is never destroyed.
Armin
Oct 30 '08 #8
If I only had your brain to pick before I start to code :-)

Thanks,

Miro

"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:uJ****************@TK2MSFTNGP06.phx.gbl...
Miro,

You can find all the mdi forms by using
\\\
me.MDIParent.MDIChildren
///

http://msdn.microsoft.com/en-us/libr...ichildren.aspx

Probably much easier,

Cor
"Miro" <mi**@beero.comschreef in bericht
news:Os****************@TK2MSFTNGP03.phx.gbl...
>>I have created myself an issue, and perhaps my idea wasn't as bright as I
thought it was originally.
If someone can help me figure out what the correct train of thought
should be - or if there is a solution to this one.

I created a dummy mdi app.
In the main form ( frmMainScreen ) I created a variable as such:
<written in notepad to trim everything down>

Public Shared frmFormsOpen() As frmMyTestForm

Now, in a totally seperate sub form opend from the main form I do this on
a button click:

LengthOfGames = (frmMainScreen.frmFormsOpen.Length - 1)
ReDim Preserve frmMainScreen.frmFormsOpen(LengthOfGames)

frmMainScreen.frmFormsOpen(LengthOfGames) = New frmMyTestForm
frmMainScreen.frmFormsOpen(LengthOfGames).MdiPare nt = Me.MdiParent
'Remember that this form is also an mdi child of the main form.
'Set my own property for later use
frmMainScreen.frmFormsOpen(LengthOfGames).GameI D = anIntegerValue

frmMainScreen.frmFormsOpen(LengthOfGames).Show( )

'Works Great
So in other code on other child forms forms I can do stuff like this:

For Each SearchForm As frmMyTestForm In
frmMainScreen.frmFormsOpen
If SearchForm.GameID = mytestID Then 'mytestID is set to a
value from something else
SearchForm.BringToFront()
Exit For
End If
Next
My problem is this:

where do i actually remove the array element when the form is closed. I
do not want it to stay in the array.
I do not think I can do it in the _FormClosed of the
frmMainScreen.frmFormsOpen(LengthOfGames)._FormCl osed
because I am actually in the form itself still - so I am assuming I
cannot kill the object when I am still using the object.
( im trying to kill myself from myself ).

That is my issue I have created myself and I was wondering if someone can
point me in the right direction on how to get around this issue.

Thanks,

Miro

Oct 30 '08 #9
Making a variable no longer point at an object does not "pull the
rug". When all references to an object go away, the object becomes
eligible to be garbage collected at some time in the future.

Forms are a little different in that the framework keeps track of them
and has a reference to all open forms (Application.OpenForms), so even
if you clear your reference there is still one being held by the
framework.

For example:

Public Class MyClass
Public A As Integer = 0
End Class

Dim x As New MyClass ' There is one reference to an instance
' of MyClass
Dim y as MyClass = x ' Now there are two references
' to the instance
x = Nothing ' Now there is one reference (y)
y = Nothing ' Now there are no references and
' the instance is eligible for garbage
' collection.

On Thu, 30 Oct 2008 10:59:30 -0400, "Miro" <mi**@beero.comwrote:
>I see,

I was the understanding that if i say
dim bla as new form1

then I was under the impression the object instantiated and the object
exists in bla which was dim'd here.

To 'remove' it from this 'dim' would be pulling the rug from under me.

As I understand your comment - the object "REFERENCE" is dim'd here, but the
actaul object exists somewhere else, so I can
"undim" my bla without worries. ( if undim was a word ) but basically
remove it from bla.

Miro

"Jack Jackson" <jj******@cinnovations.netwrote in message
news:sj********************************@4ax.com.. .
>You are confusing removing a reference to an object from a list with
destruction of the object.

An object can have many references. Removing those references does
nothing other than, when all references have been removed, make the
object available for garbage collection. It does not cause the object
to be destroyed.

And as Armin said, please don't use arrays for this. List (Of T) is
much better.

On Tue, 28 Oct 2008 23:57:20 -0400, "Miro" <mi**@beero.comwrote:
>>>Its vb 2008

Thank you for the post.
I was under the impression - since I am 'sitting' in the object still
during
_FormClose then I cannot Remove my object from underneith my feet.

Im assuming then by your statement
The object on which the current method is executed is never destroyed.
That once I leave the form and it does close - it will be destroyed in the
background - I dont need to run anything else?

I will google and search up "List" to use a list instead of an array.

Thank you,

Miro

"Armin Zingler" <az*******@freenet.dewrote in message
news:ub**************@TK2MSFTNGP02.phx.gbl...
"Miro" <mi**@beero.comschrieb
where do i actually remove the array element when the form is
closed. I do not want it to stay in the array.

Do yourself a favor and use a List(Of frmMyTestForm) instead of the
array.
(which VB version?) Safes you from item shifting and redimming.

I do not think I can do it in the _FormClosed of the
frmMainScreen.frmFormsOpen(LengthOfGames)._For mClosed
because I am actually in the form itself still - so I am assuming I
cannot kill the object when I am still using the object.
( im trying to kill myself from myself ).

You don't kill anything by removing one reference. You can safely remove
the
item from the list in the FormClosed event. The object on which the
current method is executed is never destroyed.
Armin
Oct 30 '08 #10
Thank you - excellent example for me to understand. -makes perfect sense
now.

I appreciate your time.

Thank you again,

Miro

"Jack Jackson" <jj******@cinnovations.netwrote in message
news:64********************************@4ax.com...
Making a variable no longer point at an object does not "pull the
rug". When all references to an object go away, the object becomes
eligible to be garbage collected at some time in the future.

Forms are a little different in that the framework keeps track of them
and has a reference to all open forms (Application.OpenForms), so even
if you clear your reference there is still one being held by the
framework.

For example:

Public Class MyClass
Public A As Integer = 0
End Class

Dim x As New MyClass ' There is one reference to an instance
' of MyClass
Dim y as MyClass = x ' Now there are two references
' to the instance
x = Nothing ' Now there is one reference (y)
y = Nothing ' Now there are no references and
' the instance is eligible for garbage
' collection.

On Thu, 30 Oct 2008 10:59:30 -0400, "Miro" <mi**@beero.comwrote:
>>I see,

I was the understanding that if i say
dim bla as new form1

then I was under the impression the object instantiated and the object
exists in bla which was dim'd here.

To 'remove' it from this 'dim' would be pulling the rug from under me.

As I understand your comment - the object "REFERENCE" is dim'd here, but
the
actaul object exists somewhere else, so I can
"undim" my bla without worries. ( if undim was a word ) but basically
remove it from bla.

Miro

"Jack Jackson" <jj******@cinnovations.netwrote in message
news:sj********************************@4ax.com. ..
>>You are confusing removing a reference to an object from a list with
destruction of the object.

An object can have many references. Removing those references does
nothing other than, when all references have been removed, make the
object available for garbage collection. It does not cause the object
to be destroyed.

And as Armin said, please don't use arrays for this. List (Of T) is
much better.

On Tue, 28 Oct 2008 23:57:20 -0400, "Miro" <mi**@beero.comwrote:

Its vb 2008

Thank you for the post.
I was under the impression - since I am 'sitting' in the object still
during
_FormClose then I cannot Remove my object from underneith my feet.

Im assuming then by your statement
>The object on which the current method is executed is never destroyed.
That once I leave the form and it does close - it will be destroyed in
the
background - I dont need to run anything else?

I will google and search up "List" to use a list instead of an array.

Thank you,

Miro

"Armin Zingler" <az*******@freenet.dewrote in message
news:ub**************@TK2MSFTNGP02.phx.gbl.. .
"Miro" <mi**@beero.comschrieb
>where do i actually remove the array element when the form is
>closed. I do not want it to stay in the array.
>
Do yourself a favor and use a List(Of frmMyTestForm) instead of the
array.
(which VB version?) Safes you from item shifting and redimming.
>
>I do not think I can do it in the _FormClosed of the
>frmMainScreen.frmFormsOpen(LengthOfGames)._Fo rmClosed
>because I am actually in the form itself still - so I am assuming I
>cannot kill the object when I am still using the object.
>( im trying to kill myself from myself ).
>
You don't kill anything by removing one reference. You can safely
remove
the
item from the list in the FormClosed event. The object on which the
current method is executed is never destroyed.
>
>
Armin
>
Oct 30 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Willem van Rumpt | last post by:
Hi all, coming from an unmanaged programming background, I took my time to sort out the IDisposable and finalizer patterns. Just when I thought I had it all conceptually neatly arranged, the...
10
by: Jim H | last post by:
I sometimes get the following error from my Form's Dispose Method when the application is closing: ------------------------------------------------- An unhandled exception of type...
19
by: Nathan | last post by:
I know this has been asked previously, but I've run into a situation where I need to know the difference between close and dispose, and I can't get the information I need from msdn help or previous...
35
by: Eric Sabine | last post by:
In my Finally block, I was using cn.close (where cn is an ADO.NET connection object, SQLConnection to be exact) and then I came across the following in some microsoft code. If Not cn Is Nothing...
8
by: Paul W | last post by:
Hi - in an asp.net application, how should I close out a sqlclient.connection? What combination and order of Conn.close conn.dispose conn=nothing Should I use? Specifically, is the...
3
by: Joris De Groote | last post by:
Hi, I use Adobe Acrobat to read tekst from PDF files. After that the file has been read, I move the file in a folder (using the date I got from the text I got from Acrobat). Now here is my...
54
by: Zytan | last post by:
I have a log class that makes a synchronized TextWriter like so, in the constructor: StreamWriter sw = new StreamWriter(filename); tw = TextWriter.Synchronized(sw); In the destructor,...
6
by: RFleming | last post by:
I am a pretty experienced VB programmer trying to make a jump to C#. I have created a simple (so I thought) project and seem to be stuck. I know I can create a form and write the code within the...
10
by: Miro | last post by:
I have created myself an issue, and perhaps my idea wasn't as bright as I thought it was originally. If someone can help me figure out what the correct train of thought should be - or if there is...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.