ThinkGeo.com    |     Documentation    |     Premium Support

Garbage collector error

After adding the WorldMapKit into my application, I get this error in the Garbage Collector Finalizer thread when I close the program:


Note that I have assigned projections to all feature sources generated by the RenderMap class, in order to make the maps work with our other data.   Do I need to explicitly remove those projections before I exit the program?


 
System.Reflection.TargetInvocationException was unhandled
 Message="Exception has been thrown by the target of an invocation."
 Source="mscorlib"
 StackTrace:
       at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
       at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
       at ThinkGeo.MapSuite.Core.Proj4Projection.xebc36fa7da52d8d7(IntPtr x4fa9e7eeb5ea7ffa)
       at ThinkGeo.MapSuite.Core.Proj4Projection.CloseCore()
       at ThinkGeo.MapSuite.Core.Projection.Close()
       at ThinkGeo.MapSuite.Core.Proj4Projection.x0f09c3fcb8980efd(Boolean x8d14c6905e5eb7a3)
       at ThinkGeo.MapSuite.Core.Proj4Projection.Finalize()
 InnerException: System.AccessViolationException
       Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
       Source="Proj4ExtensionX86"
       StackTrace:
            at Proj4Extension.Proj4Extensionx86.pj_free(IntPtr projPJ)
            at Proj4Extension.Proj4Extensionx86.Free(IntPtr projPJ)
       InnerException:

Ted,


 I am sorry to say I cannot reproduce the problem as you said. I added one projection for all the layers loaded from WorldMapKit as following.

Proj4Projection proj4Projection = new Proj4Projection();
proj4Projection.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
proj4Projection.ExternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(2163);

foreach (FeatureLayer layer in Map.StaticOverlay.Layers)
{
    layer.FeatureSource.Projection = proj4Projection;
}

Attachment is the screenshot. I tested a long time including open / close the app at any time. It will not throw the exception as you described.


Which version of Desktop are you testing against with World Map Kit, can you send us some codes to recreate this problem?
 
Thanks in advance!
 
Let me know if you have any problems!
 
Thanks.
 
Yale

In my initial implementation, I created a new projection object for each layer, rather than creating one projection object and sharing it across all layers.    That failed when I tried to close the the second projected that was created (and all subsequent projections).   However, I cannot replicate the problem if I immediately add another loop to close all of the projections after I create them. 
  
 I changed the implementation to use a common projection, as you have done, and that made the problem go away when the application exited.   I know that I tried that yesterday, and I was not able to get the background layers to draw, so I thought that projections might not be able to be shared.   However, I must have been doing something else wrong to create that issue. 
  
 I’m not convinced that we did not just chase a memory issue around, but we’ll drive on and hope for the best.

Ted, 
  
 Thanks for your post and sharing! 
  
 We will still keep an eye on this projection memory issue and hopefully we can find a way to recreate it later. It will be very appreciated if any hints given when it hits you.  
  
 Any other problem just let me know! 
  
 Thanks. 
  
 Yale 
  


Through additional testing, I can confirm that this problem is reproducible in our application at any time when more than one projection object is created. If I create a single projection object and share across all layers, it does not seem to occur.


I'm running version 331.



Ted,


 Yes, I can recreate the problem as you said now.
 
If I create multiple “same” projections for multiple layers, when I shut down the application, it will throw out the exception on the top of the post!

string internalProjectionString = Proj4Projection.GetEpsgParametersString(4326);
string externalProjetionString = Proj4Projection.GetEpsgParametersString(2163);

foreach (FeatureLayer layer in Map.StaticOverlay.Layers)
{
   Proj4Projection proj4Projection = new Proj4Projection(internalProjectionString, externalProjetionString);
   layer.FeatureSource.Projection = proj4Projection;
}

I have added this to our tracking working item list, hopefully we can get it fixed future.


 Thanks again for your help and ideas!
 
Any more question just let me know!
 
Yale

Yale, 
  
 I’m experiencing the same with the new build 392, what is the solution ? 
  
 Patrick.

Patrick,


The solution is all the layers should share the same projection instead of creating a projection instance for each layer.

Proj4Projection proj4Projection = new Proj4Projection();
proj4Projection.InternalProjectionParametersString Proj4Projection.GetEpsgParametersString(4326);
proj4Projection.ExternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(2163);
foreach (FeatureLayer layer in Map.StaticOverlay.Layers)
{
    layer.FeatureSource.Projection = proj4Projection;
}

 

Let me know if you have any more questions.
 
Thanks.
 
Yale


No Yale, 
  
 it’s not the solution … When using a shared single projection we are experiencing “projection is not opened” exception. 
  
 This occurs because layer.close closes the layer’s projection behind the scene and then, the projection is not open when other layers (the ones that share it) are refreshing. 
  
 Patrick.

Patrick, 
  
 Sorry for the delay and misunderstanding! 
  
 I thought you are talking about the same issue with Ted which will throw exception when use different instance for exactly same “projection”, and we have went around this issue by using a shared projection. 
  
 While it seems your problem is related with projection closed in some other threads, basically the easiest way to go around this is keeping the layer open . 
  
 Any more questions please feel free to let me know. 
  
 Thanks. 
  
 Yale 


Yale, 
  
 I’m still getting this issue too with 3.0.410; please advise. 
  
 Patrick.

Patrick,


We found a way to solve this open & close problem with writing our own shared Projection, this idea is better described in following post.
gis.thinkgeo.com/Support/Dis...fault.aspx
 
And this should be ready in next public release (since 4.0.412 probably).
 
Any more questions please feel free to let me know.
 
Thanks.
 
Yale