Sign in to follow this  
Rahul Kumar

Urgent! How to destroy the FusionMaps object?

Recommended Posts

Hi,

Does FusionMaps.js have method to destroy a specific FusionMaps object? I couldn't find it.

My page has many Flash objects, how do I release the memory for the FusionMaps I created.

var map_usa = new FusionMaps("FCMap_USA.swf", "mapusaid", "100%", "100%", "0", "0");

My page runs 24/7 and this seems to cause memory problem when creating FusionMaps object every two minutes. Right now what I do is set map_usa to undefined before I create a new one.

Appreciate for any input!

Share this post


Link to post
Share on other sites

...

Hello gwofu,

The FusionMaps created using JavaScript has two aspects that are possible reason for the memory leak. One is the JavaScript object or the other is the Flash object created by the JavaScript object.

But before we go into more details, I would like you to let me know of two things.

(1) Are you creating new Flash objects at client side on the same page itself?

(2) Do these multiple objects reside on the page at the same time or is it serial in nature? i.e. When you are creating new FusionMaps, are you either keeping or replacing the old ones?

Answers to these would allow us to address the issue in a better way.

Also, let us know about the target platform(s) and browser(s).

Edited by Guest

Share this post


Link to post
Share on other sites

The target platform is Windows XP with browser IE7. Multiple Flash objects on the same page.

 

 

 

I changed the code to create FusionMaps object only once then calling setDataXML() to update data for every 30 seconds. In this approach, the memory leak problem still exist but is much better. My app used to have Flash player crash within 12 hours, now it runs over 4 days.

 

 

 

One problem I saw is after 4 days the USA map becomes invisible, the legend is visible and move mouse around can still see the state name and data. The other problem is the memory is increasing about 80MB a day.

 

 

 

// Only called once.

 

load_fusioncharts :function (data)

 

{

 

var map1 = new FusionMaps("FCMap_USA.swf", "map1Id", "300", "300", "0", "1");

 

map1.setDataXML(data);

 

map1.render("map1div");

 

},

 

 

 

// update() is called for every 30 seconds.

 

update : function(data)

 

{

 

var mapObj = getMapFromId("map1Id");

 

if (mapObj.setDataXML)

 

{

 

mapObj.setDataXML(data);

 

data = null;

 

}

 

},

 

 

 

I wish FusionMaps team can find out what the problem is.

 

 

 

Thanks!

Share this post


Link to post
Share on other sites

...

Hello gwofu,

As I can see from your codes, you have really done well to actually not recreate the ActiveX object while calling setDataXML(). This certainly WILL reduce (if not totally stop) memory leakage.

However, for the present scenario, multiple factors are involved that control the the spatial usage of your available application memory.

  1. The browser implementation
  2. The Adobe Flash ActiveX plugin
  3. Browser's JavaScript engine
  4. FusionMaps SWF

Out of these four, we have tried to ensure that no memory is leaked/wasted with our FusionMaps swf. Everytime you call setDataXML() we have made utmost care to re-use every set of internal variables and have also taken care to ensure that all objects are disposed before re-initialization.

For the rest of the factors, we have no control!

Nevertheless, you can also send us a zipped working example of the code that you are working on, so that we can run some memory usage profiling tests and see if we could possibly optimize it.

Share this post


Link to post
Share on other sites

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

fusionChartUSA = {

 

init : true,

 

 

 

cc_init : function ()

 

{

 

var data = this.getFusionChartUSADBData();

 

data = this.toFusionMapsData(data);

 

this.load_fusioncharts(data);

 

data = null;

 

},

 

 

 

getFusionChartUSADBData : function ()

 

{

 

// ... Get data from database and store it to holder.

 

 

 

return holder

 

},

 

 

 

toFusionMapsData : function (holder)

 

{

 

var colorMap = ['FF0000', 'FF8080', 'FFA040', '40B266', '00FF00', '80FF80'];

 

var stateCounts = $(window).data('stateCounts');

 

var stateCountsSize = stateCounts.length;

 

var sectionSize = parseInt(stateCountsSize/(colorMap.length));

 

var preV = 0, tmpV;

 

var dvs = [];

 

var index = 0;

 

var legend = "";

 

 

 

if (stateCountsSize <= colorMap.length)

 

{

 

for (var i=0; i

 

{

 

legend = legend.concat("");

 

}

 

legend = legend.concat("");

 

}

 

else

 

{

 

for (var i=0; i

 

{

 

tmpV = parseInt(i/sectionSize);

 

if (preV != tmpV)

 

{

 

dvs[index] = stateCounts[i - 1];

 

index++;

 

preV = tmpV;

 

}

 

}

 

 

 

// legend

 

var dvl = dvs.length - 1;

 

 

 

for (var i=0; i

 

{

 

legend = legend.concat("");

 

}

 

legend = legend.concat("");

 

}

 

 

 

var data = "";

 

for (var x in holder)

 

{

 

data = data.concat("");

 

}

 

data = data.concat("");

 

return "" + legend + data;

 

},

 

 

 

load_fusioncharts :function (data)

 

{

 

var w = Math.round($(window).width() / 2);

 

var h = Math.round($(window).height() / 3);

 

 

 

var map1 = new FusionMaps(dashboard.root + "swf/FCMap_USA.swf", "map1Id", w, h, "0", "1");

 

map1.setDataXML(data);

 

map1.render("map1div");

 

},

 

 

 

update : function()

 

{

 

var mapObj = getMapFromId("map1Id");

 

$('#mapObj').width('100%').height('100%');

 

if (mapObj.setDataXML)

 

{

 

var data = this.getFusionChartUSADBData();

 

data = this.toFusionMapsData(data);

 

mapObj.setDataXML(data);

 

data = null;

 

}

 

},

 

 

 

unload : function()

 

{

 

var mapObj = getMapFromId("map1Id");

 

mapObj = null;

 

}

 

 

 

}

 

 

 

$(window).bind('unload', fusionChartUSA.unload);

 

 

 

fusionChartUSA.cc_init();

 

 

 

 

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this