mrmox
asked on
Array of WinForms: do I need to clean up after close before I re-use?
My project is using C# with VS2010 and .Net 4
I have a group of WinForms I am managing in an array.
if a particular WinForm has been created yet by testing for equal to null.
the user has closed it with the X in the upper right corner. However,
in this case, the array entry is NOT null, since the WinForm had existed
at one time but was closed.
1. What should I be testing to know if the WinForm was closed by the user?
2. Is it the IsDisposed?
3. Is it safe to re-use the same array location for the new re-created WinForm,
or do I have to do any cleaning up functions first?
4. What would happen if I tried to assign null to an array location if I know
the user had closed that particular WinForm?
then just some code without telling me what it is supposed to do.
And answering explicitly *each* of my numbered questions above.
Thanks!
I have a group of WinForms I am managing in an array.
// This array holds the winforms that each contain some controls
PopUpForm[] arrPopupWinFormInSrcOrder = new PopUpForm[MAX_WINFORMS];
When the array is created, all the entries are null, so I can testif a particular WinForm has been created yet by testing for equal to null.
if (PopUpForm[3] == null) { // OK to create
arrPopupWinFormInSrcOrder[3] = new PopUpForm();
}
Sometimes I need to re-create a WinForm in the same array position afterthe user has closed it with the X in the upper right corner. However,
in this case, the array entry is NOT null, since the WinForm had existed
at one time but was closed.
1. What should I be testing to know if the WinForm was closed by the user?
2. Is it the IsDisposed?
3. Is it safe to re-use the same array location for the new re-created WinForm,
or do I have to do any cleaning up functions first?
4. What would happen if I tried to assign null to an array location if I know
the user had closed that particular WinForm?
PopUpForm[3] = null;
Complete answers would be especially appreciated, explaining well ratherthen just some code without telling me what it is supposed to do.
And answering explicitly *each* of my numbered questions above.
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That's a nasty bug...was probably pretty hard to figure out! =\
ASKER
IN THE END, my problem (bug) was this: although C# does not generally destroy objects until all references to them are destroyed, and the (excellent) third-party graphing package I was using was also written in C#, something within DirectX that the third-party package had to use required that when a chart object was destroyed, all the objects referenced had to be destroyed.
I had pointed two chart objects at the same Font via reference, and deleting one of them deleted the font, in spite of the fact that another chart object was still using that font.
SO I needed to learn that for this package, I should not share any objects between its chart objects.
If anyone sees something wrong with what I've said above, please speak up (but I am not sure how since the answer was accepted).
Thanks!