Select to view content in your preferred language

Memory Management tips when multiple layers are added to AGSMapView

3685
8
Jump to solution
02-16-2012 08:26 PM
AnoopMohandas
Emerging Contributor
I have developed a GIS based iPad application.  When multiple layers added to map, app is receiving memory warning. The situation is more evident when tiled layers are added
When a tiled layer is added on top of previously added dynamic layers and tiled layers, how can I make sure only the visible map layer is fetching information or is using  memory.

The nearest match seemed to be using AGSLayerView to keep the underlying(invisible) dynamic and tiled layers hidden and then drawing only the visible?

Please provide suggestions.
0 Kudos
1 Solution

Accepted Solutions
Nicholas-Furness
Esri Regular Contributor
Hi Anoop,

Good questions. Much of this is outside the scope of this thread and forum, but I'll try to give you some pointers.

I didn't knew about generalization and our server version is 9.31. This is something we should implement on server side rite?

Yes, server-side.

And also how can we know if a layer is not generalized?

Generalization is merely the process of reducing the "resolution" of your vector data to a level that suits your purposes (in this case, rendering at given zoom levels). For example, a polyline with thousands of points in it which is good for plotting a wall-sized map may only need one tenth the number of points to look exactly the same on a small screen.

A better question might be: How do you know whether a feature class needs generalizing? Let's just consider viewing the data (editing is another issue, and the general rule is not to edit generalized data directly). And remember this discussion is for dynamic layers only (i.e. not tiled layers).

[INDENT]
Ex. 1: You could have a problem if you zoom in on a polyline or polygon layer much further than your app needs and can still see a lot of detail. That means that when you're zoomed at a working level, the data is too detailed for what you can see at that scale.

Ex. 2: You could perhaps have a polygon that is the right level of detail, but that is much larger than your visible working area. The single polygon still needs to be pulled over in its entirety for rendering. Solving that can be a whole separate discussion.

Ex. 3: You might find (as is possibly the case here) that the data is more detailed than your client specifications allow for, and so you'd want to create a generalized set of that data just for that client app.

[/INDENT]

There is a lot to consider. Client limitations, bandwidth, managing the data, data updates, editing.

The 9.3 documentation has a short discussion on the topic and overview of the operations. You will need an ArcInfo license to use most of the tools (you'll probably need "Simplify Polygon").

For 10.0, the toolset is arranged differently but attacks the same problems.

I do work with many complex layers with boundary of various states, municipalities etc. To be exact all the layers have some kind of complex irregular graphics in it 😞
If it were me, the first thing I would do is try to show that it is these complex layers that are causing your memory issue. Either use the profiler, or create a test set of generalized layers and use those.

If so, try to categorize your feature classes: "Needs generalizing" (causes a memory warning), "could do with generalizing" (takes a while to load, but doesn't cause a memory warning), and "fine as it is". That should put you in a better position to work out your next steps (and longer term data management goals if necessary).

Hope this helps a little,

Nick.

View solution in original post

0 Kudos
8 Replies
NimeshJarecha
Esri Regular Contributor
When you add any layer to the mapView, it returns a view (UIView). You can control the visibility of the layer by setting it's UIView's hidden property. You and hide the unwanted layers to avoid fetching data.

Regards,
Nimesh
0 Kudos
AnoopMohandas
Emerging Contributor
Thanks Nimesh,

So using the UIView(AGSLayerView) is the only way. I need a little more clarification, when multiple map layers are added the basemap is loaded first and the layers are redrawn from bottom to up manner rite?

If there are any dynamic layers below a tiled layer, they will be masked if a tiled layer is fully loaded so we can safely hide these "masked layers" and save network traffic and memory. The application live memory is increasing 4~5MB per layer addition. The ArcGIS SDK 2.1 performs better than 2.0.1 which used to crash in iOS 5.0.

Please do share if there are some memory management solution regarding this context.

Thanks
Anoop
0 Kudos
Nicholas-Furness
Esri Regular Contributor
Hi Anoop:

I need a little more clarification, when multiple map layers are added the basemap is loaded first and the layers are redrawn from bottom to up manner rite?

Yes. You add the bottom-most layer first and other layers are added on top in the order you add them using addMapLayer:withName:. See also the Layer Concepts Overview page for info about the Map's spatial reference.

If there are any dynamic layers below a tiled layer, they will be masked if a tiled layer is fully loaded so we can safely hide these "masked layers" and save network traffic and memory.

Not necessarily. A Tiled Layer may have transparency (see the World Transportation layer for an example). In this case, you would probably not want to hide layers added earlier in the sequence. As always, consider the data you're working with.

Please do share if there are some memory management solution regarding this context.

Here are a couple of thoughts:

Add and Remove layers:
You could consider using the AGSMapView's removeMapLayerWithName: and insertMapLayerWithName:atIndex: methods. Provided you are not somehow retaining a handle to the removed layer or layer view (you'd have to do it quite deliberately) that should help. Use the profiler to see. In my testing this helped reduce the footprint a little (although it may be no better than just hiding the layer as Nimesh suggested).

Generalize complex lines/polygons:
Note also that a Dynamic Layer will load the data as provided by the server and may cause a spike as it is loaded and rendered. If you find that you have very complex data, you could consider generalizing that data on the server end. In fact, if I add this layer (which is not generalized) and view the memory profile as it loads, it causes a spike in memory usage to well over 25Mb as the data is loaded before dropping down again once rendered. When testing against a generalized copy of the same dataset, the memory usage stays very low.

Hopefully this will help a little.

Cheers,

Nick.
0 Kudos
AnoopMohandas
Emerging Contributor
If you find that you have very complex data, you could consider generalizing that data on the server end...


Thanks Nick,
I didn't knew about generalization and our server version is 9.31. This is something we should implement on server side rite?
And also how can we know if a layer is not generalized?
I do work with many complex layers with boundary of various states, municipalities etc. To be exact all the layers have some kind of complex irregular graphics in it 😞

Regards,
Anoop
0 Kudos
Nicholas-Furness
Esri Regular Contributor
Hi Anoop,

Good questions. Much of this is outside the scope of this thread and forum, but I'll try to give you some pointers.

I didn't knew about generalization and our server version is 9.31. This is something we should implement on server side rite?

Yes, server-side.

And also how can we know if a layer is not generalized?

Generalization is merely the process of reducing the "resolution" of your vector data to a level that suits your purposes (in this case, rendering at given zoom levels). For example, a polyline with thousands of points in it which is good for plotting a wall-sized map may only need one tenth the number of points to look exactly the same on a small screen.

A better question might be: How do you know whether a feature class needs generalizing? Let's just consider viewing the data (editing is another issue, and the general rule is not to edit generalized data directly). And remember this discussion is for dynamic layers only (i.e. not tiled layers).

[INDENT]
Ex. 1: You could have a problem if you zoom in on a polyline or polygon layer much further than your app needs and can still see a lot of detail. That means that when you're zoomed at a working level, the data is too detailed for what you can see at that scale.

Ex. 2: You could perhaps have a polygon that is the right level of detail, but that is much larger than your visible working area. The single polygon still needs to be pulled over in its entirety for rendering. Solving that can be a whole separate discussion.

Ex. 3: You might find (as is possibly the case here) that the data is more detailed than your client specifications allow for, and so you'd want to create a generalized set of that data just for that client app.

[/INDENT]

There is a lot to consider. Client limitations, bandwidth, managing the data, data updates, editing.

The 9.3 documentation has a short discussion on the topic and overview of the operations. You will need an ArcInfo license to use most of the tools (you'll probably need "Simplify Polygon").

For 10.0, the toolset is arranged differently but attacks the same problems.

I do work with many complex layers with boundary of various states, municipalities etc. To be exact all the layers have some kind of complex irregular graphics in it 😞
If it were me, the first thing I would do is try to show that it is these complex layers that are causing your memory issue. Either use the profiler, or create a test set of generalized layers and use those.

If so, try to categorize your feature classes: "Needs generalizing" (causes a memory warning), "could do with generalizing" (takes a while to load, but doesn't cause a memory warning), and "fine as it is". That should put you in a better position to work out your next steps (and longer term data management goals if necessary).

Hope this helps a little,

Nick.
0 Kudos
Nicholas-Furness
Esri Regular Contributor
For 10.0, the toolset is arranged differently but attacks the same problems.


I should also point out that at ArcGIS for Server v10, you can use the maxAllowableOffset property of an AGSFeatureLayer to generalize on-the-fly. This blog post covers the topic.

Nick.
0 Kudos
AnoopMohandas
Emerging Contributor
Thanks a lot Nick :),

We discovered some unaddressed issues and the app is working fine( updated to SDK 2.1 ).

But your posts really changed the way I thought about GIS.

Since our application is a universal binary and with the launching of New iPad, we need to work out on how to leverage device capabilities.

Thanks,
Anoop
0 Kudos
DeniseKing
Esri Regular Contributor
If a post provides the answer to your question, then we encourage you to mark the post as "the answer" by activating the green check mark  right of the post. You can also "vote" on posts that you find helpful by clicking the blue caret mark. More information about the ArcGIS Discussion Forums MVP Program found here.

Thank you,
Esri Support
0 Kudos