ThinkGeo.com    |     Documentation    |     Premium Support

Memory leak in map control

We just deployed a change to an app that uses a mix of ASP.Net and MVC. It has a user control that contains an iframe that loads an MVC page with a map control on it. This user control is reloaded every time the page does a post, which is quite often. The app’s memory use is now continually climbing, indicative of a memory leak.

Since the only new thing is this use of the map control, we’re wondering if we’ve missed some basic clean up or disposal of the map control or various layers? We mostly use InMemoryFeatureLayers.

Do you have any suggestions on things we might have overlooked? We’re still on version 9.0.0.142.

Thanks!

Hi Jay,

We guess your mix have some problem, please double check whether you add this code:

protected void Page_Load(object sender, EventArgs e)
{
        if (!IsPostBack) // Please make sure you add this line
        {
              //Logic.
        }
}

And we don’t suggest you use them “mix”, if you want to create your application, you can follow our guides here:

For mvc
http://wiki.thinkgeo.com/wiki/map_suite_mvc_edition_quick_start_guide

For webForm
http://wiki.thinkgeo.com/wiki/map_suite_web_edition_quick_start_guide

If you have to choose the “mix” way, please sent us your sample project so we can look into it and help you on it.

Regards,

Don

Hi Don. I’m working on a sample project. When I get it, should I just attach it here or submit a ticket?

Hi Jay,

If the sample contains some private information, you can upload that via ticket(small file) or your FTP account(big file).

Or else you can directly upload that here.

Regards,

Don

Hi Don. My sample zips up to 9MB which is too big. Do you have an FTP site to which I can upload it?

Hi Jay,

We provide FTP account for each user, please ask support@thinkgeo.com for a FTP address or you can choose to send the data to forumsupport@thinkgeo.com.

Regards,

Don

Hi Don. I’ve emailed support asking for an FTP address and in the interim, have also emailed the project to forumsupport. There’s a README in the project which hopefully explains things.

Hi Jay,

Our developer view your code, how you used to refresh is not correct way. This way will request entire index page, which will cause our of memory.

In fact we have sample shows how to auto refresh map here:
http://samples.thinkgeo.com/MvcEdition/HowDoISamples/InteractiveOverlays/AutoRefreshOverlay/1,InteractiveOverlays

You can view source code in the web sample page, or you can download HowDoISamples from product center then view the source code there.

Regards,

Don

Hi Don. So, in our application, we have a big grid. The user can click on something in the grid, and we open a popup containing a map which displays a bunch of relevant details. The user then closes the popup, scrolls through the grid, clicks on something else, and again, we open a popup containing a map, etc The popup is a kendo window which fetches a new URL for its content, that content containing a new map.

I can modify the sample program so that the map gets created in a popup rather than directly in the page as it does now, but in essence, it’s the same thing. Are you saying that the memory leak which causes the out of memory is not fixable? Basically, any page with a map on it is going to leak memory if it gets loaded more than once?

1 Like

Hi Jay,

We test your sample. The memory leak issue isn’t an our product’s bug.

We view your code. When refreshing map, the server create a new InMemoryFeatureLayer. The InMemoryFeatureLayer is stored in memory until the app closed. So the server memory keeps growing.

If you don’t need to change the column of shape file frequently, please use ShapeFileFeatureLayer to render the map. You can rebuild the shape file, then use the new shape file to render map. Here attachment is your sample, we modified your source code, you can refer it.

https://ap.thinkgeo.com:5001/sharing/b8id9J32j

If you have any questions, please contact us.

Thanks,

Hi Don. Unfortunately, while the columns won’t change, the values associated with them will change frequently, so rebuilding the shape file won’t work.

However, what did help is using ajaxCallAction to call a method on the back end to clear the layers from the map before reloading the partial. Unfortunately, the overall trend was still upward, though admittedly, a lot slower.

After a lot of poking around, I finally found this thread and used that to remove the map from the session in the ajaxCallAction back end prior to reloading the partial, and that seems to have fixed it.

Now I just need to figure out how to incorporate this into our actual application and I should be good to go.

Hi Jay,

Thanks for your information.
Please let us know that if you meet any question when try to incorporate this solution.

Thanks
Mark

Hi Don/Mark.

I’m having some issues getting the map to be removed from the session, which is frustrating, and again, seems in a sense like a memory leak in the product: you are stuffing the map into the session, it seems like you should be responsible for removing the map from the session. Do you in fact do this, and something I’m doing is preventing it from working?

Otherwise, it seems like I should be doing this when the client-side object gets cleaned up. Poking at the OpenLayers.Map object, I see destroy(), unloadDestroy() and updateSizeDestroy() functions. Does ThinkGeo provide any hooks into those functions such that they could be used?

Hi Jay,
I guess you made your problem complex. So we create one sample to help you out this issue, please refer the attachment sample if it is your except. If there is any question, please feel free to let us know that.

MemoryLeak.zip (755.2 KB)

Thanks
Mark

Hi Mark.
Thanks for continuing to look at this. I’ve attached a sample which more accurately models our application. It simulates visiting multiple pages which each have a map on them.MemoryLeak2.zip (778.7 KB)

Hi Jay,

I read you sample code, you create every map when refresh, base on your scenario, I think you except the new maps that in new pages/dialogs when user clicking some columns. So you create many map with many InMemoryFeatureLayer. But I need to tell you that it is not one good design with MapSuite. :smile:

The best practice is:

  1. Only has one Map Control instance in you application/website;
  2. If you cannot avoid create many map control, you must avoid use InMemoryFeatureLayer. from the name, you might know that InMemoryFeatureLayeralways keep in memory. That’s why you meet this issue.

So here is your solution:

  1. Create one map, this map is hided by default;
  2. The map shows up by updated value in InMemoryFeatureLayer when user clicking some columns, and redraw the InMemoryFeatuerLayer;
  3. When closed the dialog/page, you can hide the map again.

We have created one sample with layer redraw and attached on latest reply. I think you can easy to hide map and show map in your dialog/pages.

Hoe this is helpful to you, if there is any issue, please feel free to let us know that.

Thanks
Mark

Hi Mark,

It looks like you did not include the sample in your post.

Hi Jay,

I have attached this sample on the fellow reply. please refer that and check my last reply.


If there is any issue, please feel free to contact us.

Thanks
Mark