473,324 Members | 2,456 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,324 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 1104
"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...
6
by: Simon Harris | last post by:
Hi All, Do I need to use both Conn.Close() & Conn.Dispose() when I have finished with an SQL connection? -- I am using the free version of SPAMfighter for private users. It has removed...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.