I'm calling Marshal.ReleaseComObject but com objects are still leaking. How to properly release MODI

D

DR

I'm calling Marshal.ReleaseComObject but com objects are still leaking. How
to properly release MODI.Document??

private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 1000000; i++)
{
MODI.Document miDoc = new MODI.Document();
miDoc.Create("a.gif");
miDoc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
MODI.Image tifImg = (MODI.Image)miDoc.Images[0];
string recSTring = tifImg.Layout.Text;
miDoc.Images.Remove(tifImg);
miDoc.Close(false);
System.Runtime.InteropServices.Marshal.ReleaseComObject(tifImg);
System.Runtime.InteropServices.Marshal.ReleaseComObject(miDoc);
}
}
 
S

Scott M.

1. Does the Create method of the MODI.Document return an object of some
type? If so, you are not capturing it with a variable and therefore this
object is not getting released by the CLR.

2. How do you know that you have a leak?
 
L

Laura T.

DR,

is it possible that in the line:
MODI.Image tifImg = (MODI.Image)miDoc.Images[0];

the miDoc.Images reference returns somekind COM object, a collection perhaps
(for example MODIImageCollections)?
If so, you should release also that object.. something like this:

MODIImageCollection imgColl=miDoc.Images;
MODI.Image tifImg=imgColl[0];
System.Runtime.InteropServices.Marshal.ReleaseComObject(imgColl);


DR said:
I'm calling Marshal.ReleaseComObject but com objects are still leaking.
How to properly release MODI.Document??

private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 1000000; i++)
{
MODI.Document miDoc = new MODI.Document();
miDoc.Create("a.gif");
miDoc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);
MODI.Image tifImg = (MODI.Image)miDoc.Images[0];
string recSTring = tifImg.Layout.Text;
miDoc.Images.Remove(tifImg);
miDoc.Close(false);

System.Runtime.InteropServices.Marshal.ReleaseComObject(tifImg);

System.Runtime.InteropServices.Marshal.ReleaseComObject(miDoc);
}
}
 
A

Alvin Bruney [ASP.NET MVP]

What exactly are you expecting to happen when you call releasecomobject? Out
of curiousity, you can examine the returned value from the call to determine
if there are any references left. If there are, that's a sign of a possible
leak. Otherwise, it isn't.

--

Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $19.99
 

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