By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,222 Members | 1,395 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,222 IT Pros & Developers. It's quick & easy.

Destroying ActiveX controls

P: n/a
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.
--

----------------------------------------------------
This mailbox protected from junk email by MailFrontier Desktop
from MailFrontier, Inc. http://info.mailfrontier.com
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

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

lfrmCTI = Nothing

GC.Collect()
GC.WaitForPendingFinalizers()

End If

Nov 21 '05 #2

P: n/a
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,

--
----------------------------------------------------
This mailbox protected from junk email by MailFrontier Desktop
from MailFrontier, Inc. http://info.mailfrontier.com

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:ub**************@tk2msftngp13.phx.gbl...
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

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

lfrmCTI = Nothing

GC.Collect()
GC.WaitForPendingFinalizers()

End If


Nov 21 '05 #3

P: n/a
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/architectu...l/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
Nov 21 '05 #4

P: n/a
On Fri, 13 Aug 2004 17:41:23 +1200, Peter Merwood wrote:
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.
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.