MapWindow 4 - ActiveX Control Programming : MapWindow Discussion Forum
Normally, we should release COM interfaces after we get them and don't need them again. I'm sure this rule should be also meaningful for MapWinGIS ActiveX control. For example, after calling CShapefile::get_Shape method, the caller is responsible to release the COM interface returned
Should I always release COM interface explicitly?
Posted by: Robin Liu ()
Date: October 07, 2010 11:34PM

Normally, we should release COM interfaces after we get them and don't need them again. I'm sure this rule should be also meaningful for MapWinGIS ActiveX control.

For example, after calling CShapefile::get_Shape method, the caller is responsible to release the COM interface returned by the method. Somthing like this:

Shape shape = shapeFile.Get_Shape(0);
// Do something on shape interface
Marshal.ReleaseCOMObject(shape);

Now my question is:
Is it obligatory or optional to release a COM interface explicitly?
Does CLR/GC do that for us in COM wrapper (the auto-generated interop assembly for COM)?

Options: ReplyQuote
Re: Should I always release COM interface explicitly?
Posted by: Sergei ()
Date: October 08, 2010 03:16AM

Robin,

As far as I know, .NET does this work or otherwise we would end up with huge memory leaks. It's easy to test: write C# procedure, create instance of shapefile, don't release it explicitly. Then start debug session of ocx, call the procedure and see whether destructor of the Shapefile class was called (or even track down underlying COM code to releasing the pointer).

Regards,
Sergei

Options: ReplyQuote


Sorry, only registered users may post in this forum.





Banner Exchange




GISCP.com




Send us your banner logo (160x120) for the space above, and add this MapWindow banner ad to your site:

Just paste this text in your page: