Android : Memory Getting Piled PhoneGap App

on Sunday, September 14, 2014


I have a PhoneGap / JQuery MObile App which fetches data from server thru Ajax and displays it as a list. With each Ajax fetch the Memory occupied by App increases by about 10 MB. For the first fetch it might be OK as it fetches a large number of records (around 700). However, for subsequent calls my understanding is that it should reuse the memory instead of piling up another 10 MB each time. I have used .off() to release event handlers in case they were holding the memory but no success.


Here is the main page Div where the output is displayed:



<div data-role="content" class="MainContent" style="overflow:hidden; padding-top: 0px;">
<ul data-divider-theme="b" data-role="listview" data-inset="true" class="MainMenu">

</ul>


And this is the Javascript code that fetches the data from server and displays in the above div.



AjaxFile = "mydomai.com/ajax.php";
$.get(AjaxFile, function (AjaxData) {

$( ".PL" ).off();
$(".MainMenu").off();
$(".MainContent").off();

AjaxData = '<li class="MainMenuList" data-role=list-divider>' + gTitle + AjaxData;
$(".MainMenu").empty();
$(".MainMenu").html(AjaxData);
$(".MainMenu").listview('refresh');
window.scrollTo(0, 0);
$.mobile.loading('hide');

HighlightRow(gCurrentFile);
$(document).ready(function () {
$(".PL").click(function () {
if ( !$(this).hasClass("BTitleRow") )
{
$(".PL").removeClass("RowHighlight");
$(this).addClass("RowHighlight");
OpenNewLink($(this).attr('name'));
}
});
});

});

AjaxData = null;
return;


Can someone please tell me how can I free up the memory and ensure that the same memory is reused instead of piling up more and more memory.


Many Thanks.


0 comments:

Post a Comment