Destroying ActiveX controls

  • Thread starter Thread starter Peter Merwood
  • Start date Start date
P

Peter Merwood

Hi

My VB.NET project has a Form which wraps a proprietary ActiveX control.
Efffectively the Form acts as a Class becuase the control must be placed on
a Form. The Form is not displayed by the application.

The application instantiates the Form, uses the control to connect to a
backend process disconnects, closes the Form and then performs a garbage
collection. However after four or five cycles of this the control stops
connecting to the backend process. I know the particular control to be
reliable becuase I've used it in VB6 projects without any problem. I
suspect after the Form and control is closed it's not being properly garbage
collected.

At present I've setup the following.

In the Form_Closing event I call the Control's disconnect method and then
the Control.Dispose method.

In the sub that instantiates the Form I've included the following:

If Not (lfrmCTI Is Nothing) Then
lfrmCTI.Close()
lfrmCTI.Dispose()

lfrmCTI = Nothing

GC.Collect()
GC.WaitForPendingFinalizers()

End If

Can someone tell me if this is the correct strategy to use to guarantee that
my Form and the control that it hosts will be detsroyed? Thanks.
--
 
Peter,

It seems me much to much, when it is a form, it implements Idisposable, that
means that a close should be enough because that does all the work.

I hope this helps?

Cor
 
Cor

I was hoping the Close method would take care of the destruction of the Form
and any controls (ActiveX or otherwise) that it might contain. However, I'm
not so sure about this. I'd appreciate someone telling me whether a call to
Form.Close followed by a GC.Collect is enough.

Peter,
 
Peter,

Calling the GC has nothing to do with the destruction.
The GC is to help cleaning up the managed heap.

When you will search this newsgroup or other newsgroups mostly told as
useless.

However there are people who want that there is almost 50% of memory not
used in there computer, those are often calling the GC.

To get more information see this.

http://msdn.microsoft.com/architecture/default.aspx?pull=/library/en-us/dnpag/html/scalenet.asp

This is a very large document. When you read about dispose, think than that
is about classes which do not implement Idisposable. (There will be a new
article about that in future).

Cor
 
Can someone tell me if this is the correct strategy to use to guarantee that
my Form and the control that it hosts will be detsroyed? Thanks.

I don't know if it will solve your problem, but take a look at the
Marshal.ReleaseCOMObject method. I believe that you need to call this to
release the COM object.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top