GeoMedia Discussions

Search for an answer, post a question, or answer other users' questions in our GeoMedia support discussions. This discussion board is a great way to collaborate with industry peers around the world. It is intended for discussion and support of the GeoMedia Desktop and Add-on applications.
Showing results for 
Search instead for 
Do you mean 
Reply
Contributor
Posts: 24
Registered: ‎11-06-2015
Accepted Solution

GM 2016 Marshal.FinalReleaseComObject and Marshal.ReleaseComObject

[ Edited ]

Under the What's New for Version 16.00.00 heading in the Overview section of the GeoMedia Object Reference there is a statement with respect to Marshal.FinalReleaseComObject and Marshal.ReleaseComObject. This being that these methods should no longer be used to release underlying GeoMedia COM objects and that the need for this call within the product has been resolved.

 

Does this mean that it is no longer necessary to be concerned with cleaning up GeoMedia COM object references, or is there some other method/workflow that should be employed?

Technical Evangelist
Posts: 568
Registered: ‎09-11-2015

Re: GM 2016 Marshal.FinalReleaseComObject and Marshal.ReleaseComObject

Hello Tim,

 

indeed, it is no longer necessary to release all COM objects manually, however there are some new restrictions. For example, if you have a class variables and you assign a COM objects to them, you must set them to null (C#) or Nothing (VB.NET) when you don't need them anymore, so upon exit or class destrcution. Otherwise GeoMedia crashes while colsing.

 

On the other hand, if you have an old code, the ReleaseComObjects calls can mostly stay there and your code should run OK.

 

Pavel

Staff
Posts: 5
Registered: ‎03-08-2016

Re: GM 2016 Marshal.FinalReleaseComObject and Marshal.ReleaseComObject

So let me give you a little background on why we are recommending to no longer use Marshal.ReleaseComObject. In the 2015 release cycle, we were testing the GeoMedia product line, and we experienced problems that could not be simply explained.  We spent a fair amount of time digging into it and finally found an article that brought light to the problem we were seeing.  In the article we learned about the possibility that RCW objects could be shared by other components in the product.  We found that in certain, but still not predictable locations where we were calling Marshal.ReleaseComObject on the RCW that the RCW was still being used by another object in the system causing errors to popup when the object was used.  In the 15.0 release we resolved the problems for known commands and released the product.  After the release we immediately got with Microsoft to give us guidance on determining when an object would be shared or not shared.  Needless to say the answer from them is that it is not predictable.  As a result and based on the article, we decided to remove all references to Marshal.ReleaseComObject from our code base and resolve any problems that occurred as a result of this removal.  

 

As for the reasons why we required this call in the past, the GeoMedia 15.0 and before products had a bug that required calling Marshal.ReleaseComObject so that the application could be shutdown. In the 16.0 release we have resolved all known issues with the bug.  This does not require that you remove Marshal.ReleaseComObject from your code, but due to the problems that we have seen it, we can’t guarantee that it will not break other components in the product if you continue to use it.  Please reference the link below for more information about the issues with Marsharl.ReleaseComObject.

 

https://blogs.msdn.microsoft.com/visualstudio/2010/03/01/marshal-releasecomobject-considered-dangero...

 

As for the requirement to set items to null that you have not had to do in the past, please send an example application, I would like to see what other items we may need to adjust to function better.

Technical Evangelist
Posts: 568
Registered: ‎09-11-2015

Re: GM 2016 Marshal.FinalReleaseComObject and Marshal.ReleaseComObject

Mike, I'll send you the sample command by e-mail.

 

Pavel

Occasional Contributor
Posts: 5
Registered: ‎06-01-2017

Re: GM 2016 Marshal.FinalReleaseComObject and Marshal.ReleaseComObject

[ Edited ]

Hi Pavel

 

You are writing, that geomedia crashes while closing if class variables assigned to COM objects are not set to null/nothing.

 

I am expieriencing exactly this crash after executing the following code.

 

 

Private Sub ReleaseObject(ByVal obj As Object)
        Try
            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
            obj = Nothing
        Catch ex As Exception
            obj = Nothing
        Finally
            GC.Collect()
        End Try
    End Sub

Public Sub TestReleasing(ByVal idGleisAbschnitt, ByVal dbName) Dim objMV As New Object Try geoApp = GetObject(, "Geomedia.Application") Try objMV = geoApp.ActiveWindow.MapView Catch ex As System.MissingMemberException MsgBox("Please activate MapWindow") Exit Sub Finally ReleaseObject(objMV) ReleaseObject(geoApp) End Try ReleaseObject(objMV) ReleaseObject(geoApp) Catch ex As System.MissingMemberException MsgBox("GeoMedia missing") ReleaseObject(objMV) ReleaseObject(geoApp) Exit Sub End Try End Sub

 

 

What am I doing wrong?

 

Thanks a lot for your help!

Sarah

Technical Evangelist
Posts: 568
Registered: ‎09-11-2015

Re: GM 2016 Marshal.FinalReleaseComObject and Marshal.ReleaseComObject

Hi Sarah,

 

basically, you should release each object the same time you have referenced it somehow. In your example, you may attempt to release the objects at most three times, while it is actually not clear at all how many times the objects will be attempted to release due to peculiar nesting of try...catch...finally blocks. So I suggest you to simplify the sample and everything should be smooth.

 

Pavel

Occasional Contributor
Posts: 5
Registered: ‎06-01-2017

Re: GM 2016 Marshal.FinalReleaseComObject and Marshal.ReleaseComObject

[ Edited ]

Hi Pavel

 

Thanks for your answer. As you suggested, I simplified my code to the following lines. Unfortunately Geomedia 2016 still crashes when it is beeing closed after the method has been executed. What am I doing wrong?

 

TypeLibraries: Geomedia.tlb

 

Imports Geomedia = Intergraph.GeoMedia.GeoMedia 

Public Sub TestReleasingSuperSimple() Dim geoApp As GeoMedia.Application

        geoApp = GetObject(, "Geomedia.Application")
       
Dim activeWindow As Object
        activeWindow = geoApp.ActiveWindow

        Dim objMV As Object
        objMV = activeWindow.MapView

        objMV = Nothing
        activeWindow = Nothing
        geoApp = Nothing End Sub

Thanks for your answer!

Technical Evangelist
Posts: 568
Registered: ‎09-11-2015

Re: GM 2016 Marshal.FinalReleaseComObject and Marshal.ReleaseComObject

Hi saso,

 

what version of GeoMedia are you using? I've tested your code with GM 16.1 and it quits without problems.

 

Pavel

Occasional Contributor
Posts: 5
Registered: ‎06-01-2017

Re: GM 2016 Marshal.FinalReleaseComObject and Marshal.ReleaseComObject

Hi Pavel

 

Thanks for your quick answer. I am working with a Testlicence of GeoMedia Desktop 2016 - Version 16.00.0000.01405

 

Sarah

 

 

Technical Evangelist
Posts: 568
Registered: ‎09-11-2015

Re: GM 2016 Marshal.FinalReleaseComObject and Marshal.ReleaseComObject

Hi Sarah,

 

I have tested the same with 16.0 (the same build as yours) and still everything goes fine.

 

Pavel