double totalMemoryUsed = (Runtime.getRuntime().totalMemory() + android.os.Debug.getNativeHeapAllocatedSize()); int percentUsed = (int)(totalMemoryUsed / Runtime.getRuntime().maxMemory() * 100);
I am seeing the same behavior after approximately 400 vertices added to graphic where things start to lag. At around 600-700 vertices the application freezes. This is running the following code within an Asynchronous Timer class. Any ideas on workarounds? From the ESRI samples it seems like you need to add in an entirely new graphic on each refresh and then remove the old one. Is there no way to just draw the new portion of the graphic to save memory? If not wondering if there is a workaround to "flush the graphic every so many vertices?
private void addGeometry(Point point) {
FeatureInformation pFeatureInformation = FeatureInformation.getInstance();
if (pFeatureInformation.getEditMode() != FeatureInformation.EditMode.NONE) {
pFeatureInformation.mPoints.add(point);
Integer oldGraphic = graphicID;
//workingLayer.removeAll();
if (pFeatureInformation.getEditMode() == FeatureInformation.EditMode.POINT) {
Graphic graphic = new Graphic(point, pointSymbol);
graphicID = workingLayer.addGraphic(graphic);
activeGeometry = point;
} else if (pFeatureInformation.getEditMode() == FeatureInformation.EditMode.POLYLINE) {
// **for vertex recognition
Graphic pointGraphic = new Graphic(pFeatureInformation.mPoints.get(0), pointSymbol);
graphicID = workingLayer.addGraphic(pointGraphic);
//
MultiPath multipath = new Polyline();
multipath.startPath(pFeatureInformation.mPoints.get(0));
for (int i = 1; i < pFeatureInformation.mPoints.size(); i++) {
multipath.lineTo(pFeatureInformation.mPoints.get(i));
// for vertex recognition
Graphic pointGraphic2 = new Graphic(pFeatureInformation.mPoints.get(i), pointSymbol);
graphicID = workingLayer.addGraphic(pointGraphic2);
}
Graphic graphic = new Graphic(multipath, lineSymbol);
graphicID = workingLayer.addGraphic(graphic);
activeGeometry = multipath;
} else if (pFeatureInformation.getEditMode() == FeatureInformation.EditMode.POLYGON) {
// **for vertex recognition
Graphic pointGraphic = new Graphic(
pFeatureInformation.mPoints.get(0), pointSymbol);
graphicID = workingLayer.addGraphic(pointGraphic);
//
MultiPath multipath = new Polygon();
multipath.startPath(pFeatureInformation.mPoints.get(0));
for (int i = 1; i < pFeatureInformation.mPoints.size(); i++) {
multipath.lineTo(pFeatureInformation.mPoints.get(i));
// for vertex recognition
Graphic pointGraphic2 = new Graphic(pFeatureInformation.mPoints.get(i), pointSymbol);
graphicID = workingLayer.addGraphic(pointGraphic2);
}
Graphic graphic = new Graphic(multipath, polygonSymbol);
graphicID = workingLayer.addGraphic(graphic);
activeGeometry = multipath;
}
try {
workingLayer.removeGraphic(oldGraphic);
} catch (Exception e) {
// TODO: handle exception
}
}
}
OK an update to this. We did find that by not showing vertex graphics, that memory usage is now greatly reduced. We are now able to do around 3000 vertices on a streaming line before we notice any slow down. Still think having to re-draw the entire graphic as the SDK forces you to do is inefficient and will eventually cause almost any device to slow down. However 3000 vertices seems vary reasonable as most folks will not collect features this large and we will advise setting interval to higher time for large features.
What mode are you using for your GraphicsLayer?
GraphicsLayer.RenderingMode | ArcGIS Android 10.2.6 API
This greatly affects memory usage and performance. It does also mean the user experience is slightly different, but static mode might solve your problem.