Select to view content in your preferred language

Object is already owned, C#

260
3
Jump to solution
a month ago
Labels (2)
SP2501
by
New Contributor

Running into 2 related issues

I have a map the users interact with, it uses an Operational Layer and a graphics overlay collection

Now my issue

If the user closes the map, and then comes back into the map, I run into this error.

For Graphics overlays I have been trying to clear() both the graphics layer on the map and clear() the graphics collection

EsriMapView.GraphicsOverlays.Clear();
BasicOverlays.Clear();  GraphicCollection

 

We do A WHOLE lot of stuff, and then I bomb here.

EsriMapView.GraphicsOverlays = BasicOverlays;// this is bombing on re enter

 

 

The operational layer is a little more tricky, and does NOT bomb whenever I come back in. But wont allow me to change the data or redraw the data, like if the user selects a different file to load, or changes a rendering option.

//Are we entering this again?
if (SectorLayer != null)  Not firing on reenter, but does if I try and call this method again to "redraw"
{
EsriMapView.Map.OperationalLayers.Remove(SectorLayer);
SectorLayer = null;
}
try
{
SectorLayer = new Esri.ArcGISRuntime.Mapping.FeatureLayer(BlockGroupGeoPackage.GeoPackageFeatureTables[0]); <- Bombs here
}
catch
{
MessageBox.Show("Error Adding Sector Outlines");

}
SectorLayer.Renderer = _alternateRenderer;
EsriMapView.Map.OperationalLayers.Add(SectorLayer);

 

 

Both are showing the same error, could someone help me out here understanding this? According the debug the layers are clear, the SectorLayer is Null, the graphics layers & collection are clear, and the map.operational layer is clear.

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

You have situation similar like in thread. I think BlockGroupGeoPackage.GeoPackageFeatureTables[0] makes a bomb. You need to create object from scratch, because Maps SDK saves somewhere your used objects.

View solution in original post

0 Kudos
3 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

You have situation similar like in thread. I think BlockGroupGeoPackage.GeoPackageFeatureTables[0] makes a bomb. You need to create object from scratch, because Maps SDK saves somewhere your used objects.

0 Kudos
SP2501
by
New Contributor

GK, thanks for the input! Thread helped.

0 Kudos
dotMorten_esri
Esri Notable Contributor

A Map or a GraphicsOverlay can only be attached to a single MapView instance. So when you reuse those objects, make sure they are unhooked from the old mapview.

Now this gets a little tricky because of the garbage collector meaning you don't really know when the MapView is getting collected and unhooked from the map and graphics collection. A couple approaches you can do to make that more deterministic:
1. Either reuse the same MapView across pages
2. When navigating away from the mapview page, set the Map and GraphicsOverlays properties to null to unhook them immediately and get them unowned.

 

0 Kudos