Posted 20 years ago by Peter
Avatar
Hi,

How to close a Document Window in my program?

Thanks,

Peter.

Comments (5)

Posted 20 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
DocumentWindow.Hide();


Actipro Software Support

Posted 20 years ago by Peter
Avatar
Dose DocumentWindow.Hide() release the resources used by the DocumentWindow?
If I call Hide(), then Activate(), can I bring the original DocumentWindow back?

Thanks,

Peter
Posted 20 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
A document's lifecycle is only from show to hide. To release resources you should handle the DocumentWindowClosed event. So in there you could store your child control and then create a new one to bring it back.

Tool windows are different in that their lifecycle is while the layout is active so they can be displayed and hidden many times during that period.


Actipro Software Support

Posted 20 years ago by pavigeant - Software Developer, Datahex Systems
Avatar
I would like to know how to exactly release the resource.

I create a new DockableWindow using this method. This is part of a test aplication I've done to reproduce the problem.

Private Sub cmdNewControl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNewControl.Click
  Dim dw As ActiproSoftware.DockableWindow.DWDocumentWindow
  dw = dwMain.CreateDocumentWindow(Guid.NewGuid().ToString(), "Heavy Document", _
                                   DirectCast(Nothing, Image), New usrHeavyControl)
  dw.Activate()
End Sub
usrHeavyControl is a user control that create a 2 000 000 characters string in it constructor.

Now, if I open the Windows Task Manager, I can see the memory rise up as I repeatedly press on the button. The problem is when I close a document window, the memory doesn't go down. For it to clean the control, I have to call a GC.Collect in the DocumentWindowClosed event.

Since the DocumentWindow.Child property is readonly, I cannot release the control myself. Is there is any other way to release the resources?

Thank you very much.


Pierre-Alain Vigeant
Datahex Systems Inc.
Posted 20 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
In the DocumentWindowClosed event, set a variable to the child control. Then tell it to remove from its parent and call dispose on it. Something like:

Control childControl = dw.Child;
childControl.Parent.Controls.Remove(childControl);
childControl.Dispose();
Right after our code that raises that event we set "child = null". We used to dispose the control however that was causing problems for some users so we had to take out the dispose line.


Actipro Software Support

The latest build of this product (v2.0.0208) was released 19 years ago, which was after the last post in this thread.