08-12-2016 02:08 AM - edited 08-12-2016 02:17 AM
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?
Solved! Go to Solution.
08-15-2016 05:15 AM
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.
08-16-2016 09:21 AM
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.
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.
06-01-2017 07:48 AM - edited 06-01-2017 07:49 AM
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)
obj = Nothing
Catch ex As Exception
obj = Nothing
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!
06-01-2017 08:29 AM
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.
06-06-2017 12:22 AM - edited 06-06-2017 01:25 AM
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?
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!