activeX doesn't dispose

P

Peter Proost

Hi group,

Here at work they've got an activeX control which is used on a usercontrol,
and this usercontrol is one of the standard controls in the framework, so
this user controls get's used a lot on other usercontrols or windows forms.
But the problem is the activex control doesn't get disposed. (profiled the
app with scitech .net memory profiler 2.5) I added this code to disposing
event of the base usercontrol (the one in the framework which contains the
activeX):

'Grid is the name of the activeX control
'Toegevoeg door Peter 31/03/2005
If Not Grid Is Nothing Then
Grid.Dispose()
End If
'einde toevoeging

but that doesn't help, I also tried it in the usercontrol's finalize method
but also no success. But if I create a sub in the usercontrol:

Public sub MyDispose
If Not Grid Is Nothing Then
Grid.Dispose()
End If
End sub

and then in the form's closing event of the form that hosts the usercontrol
call

myusercontrol.Mydispose

the activex control get's disposed and releases it's memory.

But now my question is isn't there a way so I can dispose the activeX
control on the usercontrol from within the user control without the extra
sub.

Greetz Peter
 
P

Peter Proost

Hi,

thnx for the answer but I've always read/heard that you shouldn't use
gc.collect, except for in some special cases, is this one of them? Because
the form containing the usercontrol get's opened and closed a lot so
gc.collect would get executed a lot and doesn't this tend to mess up the gc?
Or have I miss understand you?

Greetz Peter
 
P

Peter Proost

But I forget to mention, it was interesting but it didn't help me out :)
so I'm still puzzling

Greetz Peter
 
C

Chris Dunaway

Try something like this:

Imports System.Runtime.InteropServices

Marshal.ReleaseComObject(Grid)

Does that help?
 
P

Peter Proost

Hi thanks for the tip and I'll try that but I'm not even sure anymore if it
has to do with the Grid, because if I test it in a test app with the same
activex on a usercontrol and that usercontrol on yet another usercontrol and
that one on a form there's no problem, so I think that it's some bad coding
in some of our classes that causes the whole usercontrol not to be released.
So that's going to be some more puzzling...

Greetz Peter
 

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

Top