Maximum Number of Graphics

3333
5
04-03-2013 01:56 PM
JeanLitzebauer
New Contributor
Is there some kind of approximate maximum number of graphics that can be added to a GraphicsLayer?  I am adding one SimpleLineSymbol to my GraphicsLayer about every 50ms or so.  My application will run fine and then eventually it just freezes and returns the "application not responding" dialog.  It usually happens after about 400 or 500 lines have been added, but that number varies.  I get no feedback in Logcat or anywhere else and was just wondering if this could be because I am adding too much data.

Thanks.
0 Kudos
5 Replies
KevinGebhardt
New Contributor III
Are u adding these Graphics in a AsyncTask?
0 Kudos
DanO_Neill
Occasional Contributor III
The limitations on adding graphics is related to the memory available on your device.  Here is some code to find out how much memory your app is using. 

double totalMemoryUsed = (Runtime.getRuntime().totalMemory() + android.os.Debug.getNativeHeapAllocatedSize());
int percentUsed = (int)(totalMemoryUsed / Runtime.getRuntime().maxMemory() * 100);


I suggest you check the value of percentUsed after you add each graphic.  The percentage should be consistent when your app stops responding and that would be the limitation on your device.
0 Kudos
by Anonymous User
Not applicable

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

  }

  }

  }

0 Kudos
by Anonymous User
Not applicable

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.

0 Kudos
WillCrick
Occasional Contributor

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.

0 Kudos