AnsweredAssumed Answered

Esri.ArcGISRuntime.ArcGISRuntimeException: Object already owned.: Already owned

Question asked by nwestfall on Mar 28, 2018
Latest reply on Apr 2, 2018 by nwestfall

This is on Xamarin.Android.

 

Due to a known memory leak, we have created a static MapView and static Graphic Overlays for reuse.  We received this error when loading a "GraphicOverlay" into the MapViews "GraphicsOverlays".

 

The code that runs to load the layers

 

Snippet

App.MapView.GraphicsOverlays.Clear();    App.MapView.GraphicsOverlays.Add(_plannedRouteGraphics);  App.MapView.GraphicsOverlays.Add(_routeGraphicsLayer);  App.MapView.GraphicsOverlays.Add(_deviceRouteGraphicsLayer);  App.View.GraphicsOverlays.Add(_directionGraphics);  App.MapView.GraphicsOverlays.Add(_directionArrowGraphics);  App.MapView.GraphicsOverlays.Add(_stopGraphics);

 

Not all the time, but we from time to time get the following Exception

 

Esri.ArcGISRuntime.ArcGISRuntimeException: Object already owned.: Already owned.
Esri.ArcGISRuntime.ArcGISException.HandleCoreError ():0
RuntimeCoreNet.GeneratedWrappers.Interop.CheckError ():0
RuntimeCoreNet.GeneratedWrappers.CoreVector.Insert ():0
at Esri.ArcGISRuntime.RuntimeCollection`1+<>c__DisplayClass17_0[T].b__4 () [0x00023] in :0
Esri.ArcGISRuntime.RuntimeCollection`1[T].ExecuteActionWithUndo ():0
Esri.ArcGISRuntime.RuntimeCollection`1[T].InsertItem ():0
Esri.ArcGISRuntime.RuntimeObservableCollection`1[T].InsertItem ():0
Esri.ArcGISRuntime.RuntimeCollection`1[T].Add () : 0
Do we need to remove each of the layers one by one?  Does clear not remove the association?  Is it because the "GraphicOverlays" still have graphics in them?  Do we need to clear those Graphics first before adding them?

Outcomes