![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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).MdiParent = 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)._FormClosed 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 |
My System Specs![]() |
| | #2 (permalink) |
| | Re: formArray close / dispose issue "Miro" <miro@xxxxxx> schrieb Quote: > where do i actually remove the array element when the form is > closed. I do not want it to stay in the array. (which VB version?) Safes you from item shifting and redimming. Quote: > I do not think I can do it in the _FormClosed of the > frmMainScreen.frmFormsOpen(LengthOfGames)._FormClosed > 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 ). item from the list in the FormClosed event. The object on which the current method is executed is never destroyed. Armin |
My System Specs![]() |
| | #3 (permalink) |
| | Re: formArray close / dispose issue 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 Quote: >The object on which the current method is executed is never destroyed. 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.nospam@xxxxxx> wrote in message news:ub7GnmXOJHA.1164@xxxxxx Quote: > "Miro" <miro@xxxxxx> schrieb Quote: >> 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. > Quote: >> I do not think I can do it in the _FormClosed of the >> frmMainScreen.frmFormsOpen(LengthOfGames)._FormClosed >> 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 > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: formArray close / dispose issue "Miro" <miro@xxxxxx> schrieb Quote: > Im assuming then by your statement Quote: >>The object on which the current method is executed is never destroyed. > background - I dont need to run anything else? Quote: > I will google and search up "List" to use a list instead of an array. System.Collections.Generic.List(Of T) see also: http://msdn.microsoft.com/en-us/library/41107z8a.aspx Armin |
My System Specs![]() |
| | #5 (permalink) |
| | Re: formArray close / dispose issue 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" <miro@xxxxxx> schreef in bericht news:Osau%23rWOJHA.3732@xxxxxx Quote: >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).MdiParent = 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)._FormClosed > 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 > > > |
My System Specs![]() |
| | #6 (permalink) |
| | Re: formArray close / dispose issue 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" <miro@xxxxxx> wrote: Quote: >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 Quote: >>The object on which the current method is executed is never destroyed. >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.nospam@xxxxxx> wrote in message >news:ub7GnmXOJHA.1164@xxxxxx Quote: >> "Miro" <miro@xxxxxx> schrieb Quote: >>> 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. >> Quote: >>> I do not think I can do it in the _FormClosed of the >>> frmMainScreen.frmFormsOpen(LengthOfGames)._FormClosed >>> 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 >> |
My System Specs![]() |
| | #7 (permalink) |
| | Re: formArray close / dispose issue 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.nospam@xxxxxx> wrote in message news:ej2Ja1XOJHA.1488@xxxxxx Quote: > "Miro" <miro@xxxxxx> schrieb Quote: >> Im assuming then by your statement Quote: >>>The object on which the current method is executed is never destroyed. >> the >> background - I dont need to run anything else? > Yes, nothing else is required. > Quote: >> 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 > |
My System Specs![]() |
| | #8 (permalink) |
| | Re: formArray close / dispose issue 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" <jjackson@xxxxxx> wrote in message news:sj2hg493kpktrv5vjqr06b6a8r8tab41gv@xxxxxx Quote: > 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" <miro@xxxxxx> wrote: > Quote: >>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 Quote: >>>The object on which the current method is executed is never destroyed. >>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.nospam@xxxxxx> wrote in message >>news:ub7GnmXOJHA.1164@xxxxxx Quote: >>> "Miro" <miro@xxxxxx> schrieb >>>> 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)._FormClosed >>>> 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 >>> |
My System Specs![]() |
| | #9 (permalink) |
| | Re: formArray close / dispose issue If I only had your brain to pick before I start to code :-) Thanks, Miro "Cor Ligthert[MVP]" <notmyfirstname@xxxxxx> wrote in message news:uJ0%23R7aOJHA.4332@xxxxxx Quote: > 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" <miro@xxxxxx> schreef in bericht > news:Osau%23rWOJHA.3732@xxxxxx Quote: >>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).MdiParent = 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)._FormClosed >> 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 >> >> >> > |
My System Specs![]() |
| | #10 (permalink) |
| | Re: formArray close / dispose issue 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" <miro@xxxxxx> wrote: Quote: >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" <jjackson@xxxxxx> wrote in message >news:sj2hg493kpktrv5vjqr06b6a8r8tab41gv@xxxxxx Quote: >> 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" <miro@xxxxxx> wrote: >> Quote: >>>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.nospam@xxxxxx> wrote in message >>>news:ub7GnmXOJHA.1164@xxxxxx >>>> "Miro" <miro@xxxxxx> schrieb >>>>> 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)._FormClosed >>>>> 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 >>>> |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| How to Dispose of Old Computers Responsibly | Chillout Room | |||
File menu open/close issue | General Discussion | |||
| .net object dispose | .NET General | |||
| Dispose Unmanaged resources | .NET General | |||
| HardDisk issue, soo close to fixing it, need help | Vista hardware & devices | |||