Java script memory leak

J

Jay

I have a web app running on the windows CE device. In one of the asp.net
pages - it has javascript code. That seems to have a memory leak.
When I run the web app - in about one hour, the app hangs. I looked at the
memory and it seems to be full.
I removed all the javascript code - and the app seems to be have no leaks.
As soon as I include my javascript code - the memory consumption gradually
increases.
Whether I actually invoke the javascript code or not - it doesn't matter.
The memory leak happens.

I have been looking at some of the discussions around memory leak and they
talk about circular references and closures.
Well, I dont think I have that issue.
What else can be the problem?

Here is the page that has the problem:

<%@ Master Language="C#" AutoEventWireup="true" Inherits="MyMobile"
CodeBehind="MyMobile.master.cs" %>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<html xmlns="http://www.w3.org/1999/xhtml" >

<head id="Head1" runat="server">

<title>Untitled Page</title>

<meta http-equiv="ScannerNavigate"
content="Javascript:eek:nscan('%s','%s','%s','%s','%s');" />

</head>

<body onload="OnLoad()" onbeforeunload="showProgress();"
onunload="sip_hide();" onkeydown="cancelBack();">



<% if (this.DisplayProgress && this.DisplayTimer)

{ %>

<script language="javascript" type="text/javascript" src="<%=
Page.ResolveUrl("~/Scripts/waitTimer.js") %>">

</script>

<% } %>

<script language="javascript" type="text/javascript" src="<%=
Page.ResolveUrl("~/Scripts/button.js") %>"></script>



<script language="javascript" type="text/javascript">

var sipState = false;

var isSubmitting = false; // limits page to only one Scan or Enter
keypress, used by onkeydown method, injected via Basepage,
HandleEnterKey(...)



function sip_hide()

{

// check if CE device

if (navigator.appVersion.indexOf("Windows CE") >= 0)

{

external.CETerm.PostIDA( "IDA_SIP_HIDE", 0 );

}

}



function sip_show()

{

// check if CE device

if (navigator.appVersion.indexOf("Windows CE") >= 0)

{

external.CETerm.PostIDA( "IDA_SIP_SHOW", 0 );

return false;

}

return false;

}



function sip_toggle()

{

if (sipState == false)

{

external.CETerm.PostIDA( "IDA_SIP_SHOW", 0 );

sipState = true;

return false;

}

else

{

external.CETerm.PostIDA( "IDA_SIP_HIDE", 0 );

sipState = false;

}

}



function showProgress()

{

<% if (this.DisplayProgress) { %>

//added var since CSharp's bool in Script is

// returned as True rather than true

var bDisplayTimer = false;



<% if (this.DisplayTimer) { %>

bDisplayTimer = true;

<% } %>



displayBusyPage(bDisplayTimer);



<% } %>

}



function displayBusyPage(bTimerNeeded)

{

setTimeout('document.images["<%= ProgressImage.ClientID
%>"].src="<%= Page.ResolveUrl("~/Images/progress.gif") %>"', 200);



if (bTimerNeeded)

setTimeout("StartTimer()",10);



document.getElementById('WaitScreen').style.display ="block";

document.getElementById('Content').style.display ="none";

document.getElementById('appNavSect').style.display ="none";

document.getElementById('globalNavSect').style.display ="none";

}



// Scan Capture event

function baseScanEvent(data,source,type,time, length)

{

if (!isSubmitting) {

theForm.<%= txtScannedData.ClientID %>.value = data;

isSubmitting = true;

external.CETerm.PostIDA( "IDA_SCAN_SUSPEND", 0 );
//turn off scanner, user experience, limit to one scan per submit

theForm.submit();

}

}



var onScanEvent = function scanEvent(data,source,type,time, length)
{

baseScanEvent(data,source,type,time, length);

}



function onscan(data, source, type, time, length)

{

// external.CETerm.PostIDA( "IDA_SCAN_SUSPEND", 0 );

var inputTypeElem = document.getElementById('<%=
txtInputType.ClientID %>');

inputTypeElem.value = 'S';

var barcodeTypeElem = document.getElementById('<%=
txtBarcodeType.ClientID %>');

var btArray = source.split(':');

if (btArray.length > 1)

barcodeTypeElem.value = btArray[1];

onScanEvent(data,source,type,time,length);

}

// End Scan Capture event



// base Screen Load event - offers beep functionality

function baseLoadEvent()

{

try

{

// For Beep(s) on Windows CE

if (navigator.appVersion.indexOf("Windows CE") >= 0)

{

var count = <%= BeepCount %>;

for(var i=1; i <= count; i++)

{

<%= BeepSoundPlayString %>

for(var j=1; j<=100000; j++);

}

}

}

catch (e)

{

alert(e.message);

}

}



var onLoadEvent = function loadEvent() {

baseLoadEvent();

}

//End screen OnLoad event



// Scan Config event

function baseScanConfigEvent()

{

try

{

// First Beep on Windows CE

if (navigator.appVersion.indexOf("Windows CE") >= 0)

{

var sessIdx = external.sessionindex;



//check for any enabled symbologies

var enabledSymbologies = "<%= this.EnabledSymbologies
%>";

if (external.CETerm.ActiveSession == 3) {

if (enabledSymbologies == '') {

external.CETerm.PostIDA(
"IDA_SCAN_SUSPEND", 0 );

return;

} else {

external.CETerm.PostIDA(
"IDA_SCAN_RESUME", 0 );

}

}

var symbologies =
enabledSymbologies.split(",");



// Disable all the common symbologies

var allSymbologies = new
Array("upca","upce0","ean8","ean13","code39","code128");

for (var i=0; i < allSymbologies.length; i++) {

external.CETerm.setProperty("session"+sessIdx+".scanner."+allSymbologies+".enabled",false);

}



// Enable the required symbologies

for (var i=0; i < symbologies.length; i++) {

external.CETerm.setProperty("session"+sessIdx+".scanner."+symbologies+".enabled",true);

}



// Set the beeptime

var beepTime = <%= BeepTime %>;

external.CETerm.setProperty("session" + sessIdx +
".scanner.decodebeeptime", beepTime);



// Apply the settings

external.CETerm.PostIDA(
"IDA_SCAN_APPLYCONFIG", 0 );

}

}

catch (e)

{

alert(e.message);

}

}



var onScanConfig = function scanConfigEvent() {

baseScanConfigEvent();

}

// End Scan Config event





function OnLoad()

{

onLoadEvent();

onScanConfig();

}



function disableSelection(target) {

target.onselectstart=function() {return false}

}



function cancelBack()

{

if ((event.keyCode == 8 ||

(event.keyCode == 37 && event.altKey) ||

(event.keyCode == 39 && event.altKey))

&&

(event.srcElement.form == null || event.srcElement.isTextEdit
== false)

)

{

event.cancelBubble = true;

event.returnValue = false;

}

}



//function to toggle alert icon to "active" status

function alertRecdIcon () {

try {

document.getElementById('ctl00_GlobalNavBarArea_GlobalNavAlerts').src="<%=
Page.ResolveUrl("~/Images/new_alert_received.gif") %>";

setCookie('MWN_ALERT_ICON', '1', 1);

} catch (e) {

//ignore

}

}



//function to toggle alert icon to "normal" status

function alertNormalIcon() {

try {

document.getElementById('ctl00_GlobalNavBarArea_GlobalNavAlerts').src="<%=
Page.ResolveUrl("~/Images/alert.jpg") %>";

setCookie('MWN_ALERT_ICON', '0', 1);

} catch (e) {

//ignore

}

}



//function to handleAlert from listener app

// handleAlert must exist to receive communications from the
alerting listener client

// the 'msg' argument carries the test message of the alert

function handleAlert(type,priority,msg,id)

{

// all parameters ignored at this time

// change below to the icon that would notify of a new alert

alertRecdIcon();

}



// functions to set and get cookies -- used for alert icon state

function setCookie(c_name,value,expiredays)

{

var exdate=new Date();

exdate.setDate(exdate.getDate()+expiredays);

expiredays = null;

document.cookie=c_name+ "=" +escape(value)+"; path=/;
domain=xyz.com;"+

((expiredays==null) ? "" : ";expires="+exdate.toGMTString());

}



function getCookie(c_name)

{

if (document.cookie.length>0)

{

c_start=document.cookie.indexOf(c_name + "=");

if (c_start!=-1)

{

c_start=c_start + c_name.length+1;

c_end=document.cookie.indexOf(";",c_start);

if (c_end==-1) c_end=document.cookie.length;

return unescape(document.cookie.substring(c_start,c_end));

}

}

return "";

}



</script>



<div id="MobileScreen" class="mobileScreen">

<form id="form1" runat="server">



<input type="hidden" value="" name="txtScannedData"
id="txtScannedData" runat="server" />

<input type="hidden" value="" name="txtBarcodeType"
id="txtBarcodeType" runat="server" />

<input type="hidden" value="K" name="txtInputType"
id="txtInputType" runat="server" />



<div id="GlobalNavBar"
class="absGlobalNav">

<asp:ContentPlaceHolder ID="GlobalNavBarArea"
runat="server">

<div id="globalNavSect">

<input type="image"
name="element1" src="<%= Page.ResolveUrl("~/Images/red1px.gif") %>"
onclick="return false;"/>

<asp:ImageButton
ID="GlobalNavHome" runat="server" AlternateText="Home"
CssClass="globalNavBtn1" ImageUrl="~/Images/home.jpg" Visible="false"
OnClick="GlobalNavBarHome_Click" />

<asp:ImageButton
ID="GlobalNavScan" runat="server" AlternateText="Scan"
CssClass="globalNavBtn2" ImageUrl="~/Images/scan.jpg" Visible="false"
OnClick="GlobalNavBarScan_Click" />

<asp:ImageButton
ID="GlobalNavToggle" runat="server" AlternateText="Toggle"
CssClass="globalNavBtn2" ImageUrl="~/Images/toggle.jpg" Visible="false"
OnClick="GlobalNavBarToggle_Click" />

<asp:ImageButton
ID="GlobalNavAlerts" runat="server" AlternateText="Alerts"
CssClass="globalNavBtn3" ImageUrl="~/Images/alert.jpg" Visible="true"
OnClientClick="alertNormalIcon();" OnClick="GlobalNavBarAlerts_Click" />

<asp:ImageButton
ID="GlobalNavInfo" runat="server" AlternateText="Info"
CssClass="globalNavBtn3" ImageUrl="~/Images/info.jpg" Visible="false"
OnClick="GlobalNavBarInfo_Click" />

<asp:ImageButton
ID="GlobalNavExit" runat="server" AlternateText="Exit"
CssClass="globalNavBtn4" ImageUrl="~/Images/exit.jpg" Visible="false"
OnClick="GlobalNavBarExit_Click" />

<asp:ImageButton
ID="GlobalNavKeyboard" runat="server" AlternateText="Keyboard"
CssClass="globalNavBtn4" ImageUrl="~/Images/key.jpg" Visible="false"
OnClientClick="setFocusTxt();sip_show();return false;" />

<asp:ImageButton
ID="GlobalNavChangeView" runat="server" AlternateText="Change View"
CssClass="globalNavBtn4" ImageUrl="~/Images/change_view.jpg" Visible="false"
OnClick="GlobalNavBarChangeView_Click" />

</div>

</asp:ContentPlaceHolder>

</div>

<div id="WaitScreen"
class="absContentArea" style='display: none'>

<table border="0" width="100%">

<tr align="center">

<td align="center">

<asp:Image
ID="ProgressImage" ImageAlign="absmiddle" ImageUrl="~/Images/progress.gif"
AlternateText="In Progress" runat="server"/>

<!--img
id="ProgressImage" align=absmiddle src="/Images/progress.gif" alt="In
Progress" /-->

</td>

</tr>

<tr align="center"
valign="top">

<td align="center"
valign="top">

<font face="Tahoma"
style="font-weight:bold" size="3"><%= BusyMessage %></font>

<% if
(this.DisplayTimer) { %>

<br /><br />

<span id="time"
class="waitTimer">

&nbsp;&nbsp;

</span>

<% } %>

</td>

</tr>

</table>

</div>

<div id="Content"
class="absContentArea">

<asp:ContentPlaceHolder ID="ContentArea" runat="server" >

<h3>Default Content</h3>

</asp:ContentPlaceHolder>

</div>

<div id="AppNavBar" class="appNav">

<asp:ContentPlaceHolder ID="AppNavBarArea" runat="server">

<div id="appNavSect">

<asp:ImageButton ID="AppNavBarBack" runat="server"
AlternateText="Back" CssClass="appNavBtn1" ImageUrl="~/Images/Back.jpg"
Visible="false" OnClick="AppNavBarBack_Click" />

<asp:ImageButton ID="AppNavBarUp" runat="server"
AlternateText="Up" CssClass="appNavBtn2" ImageUrl="~/Images/up.jpg"
Visible="false" OnClick="AppNavBarUp_Click" />

<asp:ImageButton ID="AppNavBarDown" runat="server"
AlternateText="Down" CssClass="appNavBtn3" ImageUrl="~/Images/down.jpg"
Visible="false" OnClick="AppNavBarDown_Click" />

<asp:ImageButton ID="AppNavBarNext" runat="server"
AlternateText="Next" CssClass="appNavBtn4" ImageUrl="~/Images/next.jpg"
Visible="false" OnClick="AppNavBarNext_Click" />

<asp:ImageButton ID="AppNavBarGo" runat="server"
AlternateText="Go" CssClass="appNavBtn4" ImageUrl="~/Images/go.gif"
Visible="false" OnClick="AppNavBarGo_Click" />

</div>

</asp:ContentPlaceHolder>

<div class="ScreenID"><asp:Label ID="lblScreenID"
runat="server"></asp:Label></div>

</div>

</form>



<script language="javascript" type="text/javascript">

var theForm = document.forms['aspnetForm'];

if (!theForm) {

theForm = document.aspnetForm;

}

</script>



</div>

<script type="text/javascript" language="javascript">

disableSelection(document.getElementById("MobileScreen"));



//set alert icon based on cookie

if (getCookie('MWN_ALERT_ICON')=='1') {

alertRecdIcon();

} else {

alertNormalIcon();

}

</script>

</body>

</html>
 
M

Michael Nemtsev [MVP]

Hello Jay,

it's definetely the JS leaking.
I recommend to use these tools and try to detect where exactly it's leaking
http://blogs.msdn.com/ie/archive/2007/11/29/tools-for-detecting-memory-leaks.aspx

---
WBR,
Michael Nemtsev [Microsoft MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


J> I have a web app running on the windows CE device. In one of the
J> asp.net
J> pages - it has javascript code. That seems to have a memory leak.
J> When I run the web app - in about one hour, the app hangs. I looked
J> at the
J> memory and it seems to be full.
J> I removed all the javascript code - and the app seems to be have no
J> leaks.
J> As soon as I include my javascript code - the memory consumption
J> gradually
J> increases.
J> Whether I actually invoke the javascript code or not - it doesn't
J> matter.
J> The memory leak happens.
J> I have been looking at some of the discussions around memory leak and
J> they
J> talk about circular references and closures.
J> Well, I dont think I have that issue.
J> What else can be the problem?
J> Here is the page that has the problem:
J>
J> <%@ Master Language="C#" AutoEventWireup="true" Inherits="MyMobile"
J> CodeBehind="MyMobile.master.cs" %>
J>
J> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
J> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
J>
J> <html xmlns="http://www.w3.org/1999/xhtml" >
J>
J> <head id="Head1" runat="server">
J>
J> <title>Untitled Page</title>
J>
J> <meta http-equiv="ScannerNavigate"
J> content="Javascript:eek:nscan('%s','%s','%s','%s','%s');" />
J>
J> </head>
J>
J> <body onload="OnLoad()" onbeforeunload="showProgress();"
J> onunload="sip_hide();" onkeydown="cancelBack();">
J>
J> <% if (this.DisplayProgress && this.DisplayTimer)
J>
J> { %>
J>
J> <script language="javascript" type="text/javascript" src="<%=
J> Page.ResolveUrl("~/Scripts/waitTimer.js") %>">
J>
J> </script>
J>
J> <% } %>
J>
J> <script language="javascript" type="text/javascript" src="<%=
J> Page.ResolveUrl("~/Scripts/button.js") %>"></script>
J>
J> <script language="javascript" type="text/javascript">
J>
J> var sipState = false;
J>
J> var isSubmitting = false; // limits page to only one Scan or
J> Enter keypress, used by onkeydown method, injected via Basepage,
J> HandleEnterKey(...)
J>
J> function sip_hide()
J>
J> {
J>
J> // check if CE device
J>
J> if (navigator.appVersion.indexOf("Windows CE") >= 0)
J>
J> {
J>
J> external.CETerm.PostIDA( "IDA_SIP_HIDE", 0 );
J>
J> }
J>
J> }
J>
J> function sip_show()
J>
J> {
J>
J> // check if CE device
J>
J> if (navigator.appVersion.indexOf("Windows CE") >= 0)
J>
J> {
J>
J> external.CETerm.PostIDA( "IDA_SIP_SHOW", 0 );
J>
J> return false;
J>
J> }
J>
J> return false;
J>
J> }
J>
J> function sip_toggle()
J>
J> {
J>
J> if (sipState == false)
J>
J> {
J>
J> external.CETerm.PostIDA( "IDA_SIP_SHOW", 0 );
J>
J> sipState = true;
J>
J> return false;
J>
J> }
J>
J> else
J>
J> {
J>
J> external.CETerm.PostIDA( "IDA_SIP_HIDE", 0 );
J>
J> sipState = false;
J>
J> }
J>
J> }
J>
J> function showProgress()
J>
J> {
J>
J> <% if (this.DisplayProgress) { %>
J>
J> //added var since CSharp's bool in Script is
J>
J> // returned as True rather than true
J>
J> var bDisplayTimer = false;
J>
J> <% if (this.DisplayTimer) { %>
J>
J> bDisplayTimer = true;
J>
J> <% } %>
J>
J> displayBusyPage(bDisplayTimer);
J>
J> <% } %>
J>
J> }
J>
J> function displayBusyPage(bTimerNeeded)
J>
J> {
J>
J> setTimeout('document.images["<%= ProgressImage.ClientID
J> %>"].src="<%= Page.ResolveUrl("~/Images/progress.gif") %>"', 200);
J>
J> if (bTimerNeeded)
J>
J> setTimeout("StartTimer()",10);
J>
J> document.getElementById('WaitScreen').style.display
J> ="block";
J>
J> document.getElementById('Content').style.display ="none";
J>
J> document.getElementById('appNavSect').style.display
J> ="none";
J>
J> document.getElementById('globalNavSect').style.display
J> ="none";
J>
J> }
J>
J> // Scan Capture event
J>
J> function baseScanEvent(data,source,type,time, length)
J>
J> {
J>
J> if (!isSubmitting) {
J>
J> theForm.<%= txtScannedData.ClientID %>.value = data;
J>
J> isSubmitting = true;
J>
J> external.CETerm.PostIDA( "IDA_SCAN_SUSPEND", 0 );
J> //turn off scanner, user experience, limit to one scan per submit
J>
J> theForm.submit();
J>
J> }
J>
J> }
J>
J> var onScanEvent = function scanEvent(data,source,type,time,
J> length) {
J>
J> baseScanEvent(data,source,type,time,
J> length);
J>
J> }
J>
J> function onscan(data, source, type, time, length)
J>
J> {
J>
J> // external.CETerm.PostIDA( "IDA_SCAN_SUSPEND", 0 );
J>
J> var inputTypeElem = document.getElementById('<%=
J> txtInputType.ClientID %>');
J>
J> inputTypeElem.value = 'S';
J>
J> var barcodeTypeElem = document.getElementById('<%=
J> txtBarcodeType.ClientID %>');
J>
J> var btArray = source.split(':');
J>
J> if (btArray.length > 1)
J>
J> barcodeTypeElem.value = btArray[1];
J>
J> onScanEvent(data,source,type,time,length);
J>
J> }
J>
J> // End Scan Capture event
J>
J> // base Screen Load event - offers beep functionality
J>
J> function baseLoadEvent()
J>
J> {
J>
J> try
J>
J> {
J>
J> // For Beep(s) on Windows CE
J>
J> if (navigator.appVersion.indexOf("Windows CE") >= 0)
J>
J> {
J>
J> var count = <%= BeepCount %>;
J>
J> for(var i=1; i <= count; i++)
J>
J> {
J>
J> <%= BeepSoundPlayString %>
J>
J> for(var j=1; j<=100000; j++);
J>
J> }
J>
J> }
J>
J> }
J>
J> catch (e)
J>
J> {
J>
J> alert(e.message);
J>
J> }
J>
J> }
J>
J> var onLoadEvent = function loadEvent() {
J>
J> baseLoadEvent();
J>
J> }
J>
J> //End screen OnLoad event
J>
J> // Scan Config event
J>
J> function baseScanConfigEvent()
J>
J> {
J>
J> try
J>
J> {
J>
J> // First Beep on Windows CE
J>
J> if (navigator.appVersion.indexOf("Windows CE") >= 0)
J>
J> {
J>
J> var sessIdx = external.sessionindex;
J>
J> //check for any enabled symbologies
J>
J> var enabledSymbologies = "<%=
J> this.EnabledSymbologies %>";
J>
J> if (external.CETerm.ActiveSession == 3) {
J>
J> if (enabledSymbologies == '')
J> {
J>
J> external.CETerm.PostIDA(
J> "IDA_SCAN_SUSPEND", 0 );
J>
J> return;
J>
J> } else {
J>
J> external.CETerm.PostIDA(
J> "IDA_SCAN_RESUME", 0 );
J>
J> }
J>
J> }
J>
J> var symbologies =
J> enabledSymbologies.split(",");
J>
J> // Disable all the common symbologies
J>
J> var allSymbologies = new
J> Array("upca","upce0","ean8","ean13","code39","code128");
J>
J> for (var i=0; i < allSymbologies.length; i++) {
J>
J>
J> external.CETerm.setProperty("session"+sessIdx+".scanner."+allSymbolog
J> ies+".enabled",false);
J>
J> }
J>
J> // Enable the required
J> symbologies
J>
J> for (var i=0; i < symbologies.length; i++) {
J>
J>
J> external.CETerm.setProperty("session"+sessIdx+".scanner."+symbologies
J> +".enabled",true);
J>
J> }
J>
J> // Set the beeptime
J>
J> var beepTime = <%= BeepTime %>;
J>
J> external.CETerm.setProperty("session" + sessIdx +
J> ".scanner.decodebeeptime", beepTime);
J>
J> // Apply the settings
J>
J> external.CETerm.PostIDA(
J> "IDA_SCAN_APPLYCONFIG", 0 );
J>
J> }
J>
J> }
J>
J> catch (e)
J>
J> {
J>
J> alert(e.message);
J>
J> }
J>
J> }
J>
J> var onScanConfig = function scanConfigEvent() {
J>
J> baseScanConfigEvent();
J>
J> }
J>
J> // End Scan Config event
J>
J> function OnLoad()
J>
J> {
J>
J> onLoadEvent();
J>
J> onScanConfig();
J>
J> }
J>
J> function disableSelection(target) {
J>
J> target.onselectstart=function() {return false}
J>
J> }
J>
J> function cancelBack()
J>
J> {
J>
J> if ((event.keyCode == 8 ||
J>
J> (event.keyCode == 37 && event.altKey) ||
J>
J> (event.keyCode == 39 && event.altKey))
J>
J> &&
J>
J> (event.srcElement.form == null ||
J> event.srcElement.isTextEdit == false)
J>
J> )
J>
J> {
J>
J> event.cancelBubble = true;
J>
J> event.returnValue = false;
J>
J> }
J>
J> }
J>
J> //function to toggle alert icon to "active" status
J>
J> function alertRecdIcon () {
J>
J> try {
J>
J>
J> document.getElementById('ctl00_GlobalNavBarArea_GlobalNavAlerts').src
J> ="<%= Page.ResolveUrl("~/Images/new_alert_received.gif") %>";
J>
J> setCookie('MWN_ALERT_ICON', '1', 1);
J>
J> } catch (e) {
J>
J> //ignore
J>
J> }
J>
J> }
J>
J> //function to toggle alert icon to "normal" status
J>
J> function alertNormalIcon() {
J>
J> try {
J>
J>
J> document.getElementById('ctl00_GlobalNavBarArea_GlobalNavAlerts').src
J> ="<%= Page.ResolveUrl("~/Images/alert.jpg") %>";
J>
J> setCookie('MWN_ALERT_ICON', '0', 1);
J>
J> } catch (e) {
J>
J> //ignore
J>
J> }
J>
J> }
J>
J> //function to handleAlert from listener app
J>
J> // handleAlert must exist to receive communications from the
J> alerting listener client
J>
J> // the 'msg' argument carries the test message of the alert
J>
J> function handleAlert(type,priority,msg,id)
J>
J> {
J>
J> // all parameters ignored at this time
J>
J> // change below to the icon that would notify of a new
J> alert
J>
J> alertRecdIcon();
J>
J> }
J>
J> // functions to set and get cookies -- used for alert icon
J> state
J>
J> function setCookie(c_name,value,expiredays)
J>
J> {
J>
J> var exdate=new Date();
J>
J> exdate.setDate(exdate.getDate()+expiredays);
J>
J> expiredays = null;
J>
J> document.cookie=c_name+ "=" +escape(value)+"; path=/;
J> domain=xyz.com;"+
J>
J> ((expiredays==null) ? "" :
J> ";expires="+exdate.toGMTString());
J>
J> }
J>
J> function getCookie(c_name)
J>
J> {
J>
J> if (document.cookie.length>0)
J>
J> {
J>
J> c_start=document.cookie.indexOf(c_name + "=");
J>
J> if (c_start!=-1)
J>
J> {
J>
J> c_start=c_start + c_name.length+1;
J>
J> c_end=document.cookie.indexOf(";",c_start);
J>
J> if (c_end==-1) c_end=document.cookie.length;
J>
J> return
J> unescape(document.cookie.substring(c_start,c_end));
J>
J> }
J>
J> }
J>
J> return "";
J>
J> }
J>
J> </script>
J>
J> <div id="MobileScreen" class="mobileScreen">
J>
J> <form id="form1" runat="server">
J>
J> <input type="hidden" value="" name="txtScannedData"
J> id="txtScannedData" runat="server" />
J>
J> <input type="hidden" value="" name="txtBarcodeType"
J> id="txtBarcodeType" runat="server" />
J>
J> <input type="hidden" value="K" name="txtInputType"
J> id="txtInputType" runat="server" />
J>
J> <div id="GlobalNavBar"
J> class="absGlobalNav">
J>
J> <asp:ContentPlaceHolder ID="GlobalNavBarArea"
J> runat="server">
J>
J> <div id="globalNavSect">
J>
J> <input
J> type="image" name="element1" src="<%=
J> Page.ResolveUrl("~/Images/red1px.gif") %>" onclick="return false;"/>
J>
J> <asp:ImageButton
J> ID="GlobalNavHome" runat="server" AlternateText="Home"
J> CssClass="globalNavBtn1" ImageUrl="~/Images/home.jpg" Visible="false"
J> OnClick="GlobalNavBarHome_Click" />
J>
J>
J> <asp:ImageButton ID="GlobalNavScan" runat="server"
J> AlternateText="Scan" CssClass="globalNavBtn2"
J> ImageUrl="~/Images/scan.jpg" Visible="false"
J> OnClick="GlobalNavBarScan_Click" />
J>
J>
J> <asp:ImageButton ID="GlobalNavToggle" runat="server"
J> AlternateText="Toggle" CssClass="globalNavBtn2"
J> ImageUrl="~/Images/toggle.jpg" Visible="false"
J> OnClick="GlobalNavBarToggle_Click" />
J>
J>
J> <asp:ImageButton ID="GlobalNavAlerts" runat="server"
J> AlternateText="Alerts" CssClass="globalNavBtn3"
J> ImageUrl="~/Images/alert.jpg" Visible="true"
J> OnClientClick="alertNormalIcon();" OnClick="GlobalNavBarAlerts_Click"
J> />
J>
J>
J> <asp:ImageButton ID="GlobalNavInfo" runat="server"
J> AlternateText="Info" CssClass="globalNavBtn3"
J> ImageUrl="~/Images/info.jpg" Visible="false"
J> OnClick="GlobalNavBarInfo_Click" />
J>
J>
J> <asp:ImageButton ID="GlobalNavExit" runat="server"
J> AlternateText="Exit" CssClass="globalNavBtn4"
J> ImageUrl="~/Images/exit.jpg" Visible="false"
J> OnClick="GlobalNavBarExit_Click" />
J>
J>
J> <asp:ImageButton ID="GlobalNavKeyboard" runat="server"
J> AlternateText="Keyboard" CssClass="globalNavBtn4"
J> ImageUrl="~/Images/key.jpg" Visible="false"
J> OnClientClick="setFocusTxt();sip_show();return false;" />
J>
J>
J> <asp:ImageButton ID="GlobalNavChangeView" runat="server"
J> AlternateText="Change View" CssClass="globalNavBtn4"
J> ImageUrl="~/Images/change_view.jpg" Visible="false"
J> OnClick="GlobalNavBarChangeView_Click" />
J>
J> </div>
J>
J> </asp:ContentPlaceHolder>
J>
J> </div>
J>
J> <div id="WaitScreen"
J> class="absContentArea" style='display: none'>
J>
J> <table border="0"
J> width="100%">
J>
J> <tr align="center">
J>
J> <td align="center">
J>
J> <asp:Image
J> ID="ProgressImage" ImageAlign="absmiddle"
J> ImageUrl="~/Images/progress.gif" AlternateText="In Progress"
J> runat="server"/>
J>
J> <!--img
J> id="ProgressImage" align=absmiddle src="/Images/progress.gif" alt="In
J> Progress" /-->
J>
J> </td>
J>
J> </tr>
J>
J> <tr align="center"
J> valign="top">
J>
J> <td align="center"
J> valign="top">
J>
J> <font
J> face="Tahoma" style="font-weight:bold" size="3"><%= BusyMessage
J> %></font>
J>
J> <% if
J> (this.DisplayTimer) { %>
J>
J> <br /><br />
J>
J> <span
J> id="time" class="waitTimer">
J>
J> &nbsp;&nbsp;
J>
J> </span>
J>
J> <% } %>
J>
J> </td>
J>
J> </tr>
J>
J> </table>
J>
J> </div>
J>
J> <div id="Content"
J> class="absContentArea">
J>
J> <asp:ContentPlaceHolder ID="ContentArea"
J> runat="server" >
J>
J> <h3>Default Content</h3>
J>
J> </asp:ContentPlaceHolder>
J>
J> </div>
J>
J> <div id="AppNavBar"
J> class="appNav">
J>
J> <asp:ContentPlaceHolder ID="AppNavBarArea"
J> runat="server">
J>
J> <div id="appNavSect">
J>
J> <asp:ImageButton ID="AppNavBarBack"
J> runat="server" AlternateText="Back" CssClass="appNavBtn1"
J> ImageUrl="~/Images/Back.jpg" Visible="false"
J> OnClick="AppNavBarBack_Click" />
J>
J> <asp:ImageButton ID="AppNavBarUp" runat="server"
J> AlternateText="Up" CssClass="appNavBtn2" ImageUrl="~/Images/up.jpg"
J> Visible="false" OnClick="AppNavBarUp_Click" />
J>
J> <asp:ImageButton ID="AppNavBarDown"
J> runat="server" AlternateText="Down" CssClass="appNavBtn3"
J> ImageUrl="~/Images/down.jpg" Visible="false"
J> OnClick="AppNavBarDown_Click" />
J>
J> <asp:ImageButton ID="AppNavBarNext"
J> runat="server" AlternateText="Next" CssClass="appNavBtn4"
J> ImageUrl="~/Images/next.jpg" Visible="false"
J> OnClick="AppNavBarNext_Click" />
J>
J> <asp:ImageButton ID="AppNavBarGo" runat="server"
J> AlternateText="Go" CssClass="appNavBtn4" ImageUrl="~/Images/go.gif"
J> Visible="false" OnClick="AppNavBarGo_Click" />
J>
J> </div>
J>
J> </asp:ContentPlaceHolder>
J>
J> <div class="ScreenID"><asp:Label ID="lblScreenID"
J> runat="server"></asp:Label></div>
J>
J> </div>
J>
J> </form>
J>
J> <script language="javascript"
J> type="text/javascript">
J>
J> var theForm = document.forms['aspnetForm'];
J>
J> if (!theForm) {
J>
J> theForm = document.aspnetForm;
J>
J> }
J>
J> </script>
J>
J> </div>
J>
J> <script type="text/javascript" language="javascript">
J>
J> disableSelection(document.getElementById("MobileScreen"));
J>
J> //set alert icon based on cookie
J>
J> if (getCookie('MWN_ALERT_ICON')=='1') {
J>
J> alertRecdIcon();
J>
J> } else {
J>
J> alertNormalIcon();
J>
J> }
J>
J> </script>
J>
J> </body>
J>
J> </html>
J>
 
A

Alvin Bruney [ASP.NET MVP]

How do you stop the timer, I don't see it in the code.

--

Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $19.99
-------------------------------------------------------


Jay said:
I have a web app running on the windows CE device. In one of the asp.net
pages - it has javascript code. That seems to have a memory leak.
When I run the web app - in about one hour, the app hangs. I looked at the
memory and it seems to be full.
I removed all the javascript code - and the app seems to be have no leaks.
As soon as I include my javascript code - the memory consumption gradually
increases.
Whether I actually invoke the javascript code or not - it doesn't matter.
The memory leak happens.

I have been looking at some of the discussions around memory leak and they
talk about circular references and closures.
Well, I dont think I have that issue.
What else can be the problem?

Here is the page that has the problem:

<%@ Master Language="C#" AutoEventWireup="true" Inherits="MyMobile"
CodeBehind="MyMobile.master.cs" %>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<html xmlns="http://www.w3.org/1999/xhtml" >

<head id="Head1" runat="server">

<title>Untitled Page</title>

<meta http-equiv="ScannerNavigate"
content="Javascript:eek:nscan('%s','%s','%s','%s','%s');" />

</head>

<body onload="OnLoad()" onbeforeunload="showProgress();"
onunload="sip_hide();" onkeydown="cancelBack();">



<% if (this.DisplayProgress && this.DisplayTimer)

{ %>

<script language="javascript" type="text/javascript" src="<%=
Page.ResolveUrl("~/Scripts/waitTimer.js") %>">

</script>

<% } %>

<script language="javascript" type="text/javascript" src="<%=
Page.ResolveUrl("~/Scripts/button.js") %>"></script>



<script language="javascript" type="text/javascript">

var sipState = false;

var isSubmitting = false; // limits page to only one Scan or Enter
keypress, used by onkeydown method, injected via Basepage,
HandleEnterKey(...)



function sip_hide()

{

// check if CE device

if (navigator.appVersion.indexOf("Windows CE") >= 0)

{

external.CETerm.PostIDA( "IDA_SIP_HIDE", 0 );

}

}



function sip_show()

{

// check if CE device

if (navigator.appVersion.indexOf("Windows CE") >= 0)

{

external.CETerm.PostIDA( "IDA_SIP_SHOW", 0 );

return false;

}

return false;

}



function sip_toggle()

{

if (sipState == false)

{

external.CETerm.PostIDA( "IDA_SIP_SHOW", 0 );

sipState = true;

return false;

}

else

{

external.CETerm.PostIDA( "IDA_SIP_HIDE", 0 );

sipState = false;

}

}



function showProgress()

{

<% if (this.DisplayProgress) { %>

//added var since CSharp's bool in Script is

// returned as True rather than true

var bDisplayTimer = false;



<% if (this.DisplayTimer) { %>

bDisplayTimer = true;

<% } %>



displayBusyPage(bDisplayTimer);



<% } %>

}



function displayBusyPage(bTimerNeeded)

{

setTimeout('document.images["<%= ProgressImage.ClientID
%>"].src="<%= Page.ResolveUrl("~/Images/progress.gif") %>"', 200);



if (bTimerNeeded)

setTimeout("StartTimer()",10);



document.getElementById('WaitScreen').style.display ="block";

document.getElementById('Content').style.display ="none";

document.getElementById('appNavSect').style.display ="none";

document.getElementById('globalNavSect').style.display ="none";

}



// Scan Capture event

function baseScanEvent(data,source,type,time, length)

{

if (!isSubmitting) {

theForm.<%= txtScannedData.ClientID %>.value = data;

isSubmitting = true;

external.CETerm.PostIDA( "IDA_SCAN_SUSPEND", 0 ); //turn
off scanner, user experience, limit to one scan per submit

theForm.submit();

}

}



var onScanEvent = function scanEvent(data,source,type,time, length)
{

baseScanEvent(data,source,type,time, length);

}



function onscan(data, source, type, time, length)

{

// external.CETerm.PostIDA( "IDA_SCAN_SUSPEND", 0 );

var inputTypeElem = document.getElementById('<%=
txtInputType.ClientID %>');

inputTypeElem.value = 'S';

var barcodeTypeElem = document.getElementById('<%=
txtBarcodeType.ClientID %>');

var btArray = source.split(':');

if (btArray.length > 1)

barcodeTypeElem.value = btArray[1];

onScanEvent(data,source,type,time,length);

}

// End Scan Capture event



// base Screen Load event - offers beep functionality

function baseLoadEvent()

{

try

{

// For Beep(s) on Windows CE

if (navigator.appVersion.indexOf("Windows CE") >= 0)

{

var count = <%= BeepCount %>;

for(var i=1; i <= count; i++)

{

<%= BeepSoundPlayString %>

for(var j=1; j<=100000; j++);

}

}

}

catch (e)

{

alert(e.message);

}

}



var onLoadEvent = function loadEvent() {

baseLoadEvent();

}

//End screen OnLoad event



// Scan Config event

function baseScanConfigEvent()

{

try

{

// First Beep on Windows CE

if (navigator.appVersion.indexOf("Windows CE") >= 0)

{

var sessIdx = external.sessionindex;



//check for any enabled symbologies

var enabledSymbologies = "<%= this.EnabledSymbologies
%>";

if (external.CETerm.ActiveSession == 3) {

if (enabledSymbologies == '') {

external.CETerm.PostIDA(
"IDA_SCAN_SUSPEND", 0 );

return;

} else {

external.CETerm.PostIDA(
"IDA_SCAN_RESUME", 0 );

}

}

var symbologies =
enabledSymbologies.split(",");



// Disable all the common symbologies

var allSymbologies = new
Array("upca","upce0","ean8","ean13","code39","code128");

for (var i=0; i < allSymbologies.length; i++) {


external.CETerm.setProperty("session"+sessIdx+".scanner."+allSymbologies+".enabled",false);

}



// Enable the required symbologies

for (var i=0; i < symbologies.length; i++) {


external.CETerm.setProperty("session"+sessIdx+".scanner."+symbologies+".enabled",true);

}



// Set the beeptime

var beepTime = <%= BeepTime %>;

external.CETerm.setProperty("session" + sessIdx +
".scanner.decodebeeptime", beepTime);



// Apply the settings

external.CETerm.PostIDA(
"IDA_SCAN_APPLYCONFIG", 0 );

}

}

catch (e)

{

alert(e.message);

}

}



var onScanConfig = function scanConfigEvent() {

baseScanConfigEvent();

}

// End Scan Config event





function OnLoad()

{

onLoadEvent();

onScanConfig();

}



function disableSelection(target) {

target.onselectstart=function() {return false}

}



function cancelBack()

{

if ((event.keyCode == 8 ||

(event.keyCode == 37 && event.altKey) ||

(event.keyCode == 39 && event.altKey))

&&

(event.srcElement.form == null ||
event.srcElement.isTextEdit == false)

)

{

event.cancelBubble = true;

event.returnValue = false;

}

}



//function to toggle alert icon to "active" status

function alertRecdIcon () {

try {


document.getElementById('ctl00_GlobalNavBarArea_GlobalNavAlerts').src="<%=
Page.ResolveUrl("~/Images/new_alert_received.gif") %>";

setCookie('MWN_ALERT_ICON', '1', 1);

} catch (e) {

//ignore

}

}



//function to toggle alert icon to "normal" status

function alertNormalIcon() {

try {


document.getElementById('ctl00_GlobalNavBarArea_GlobalNavAlerts').src="<%=
Page.ResolveUrl("~/Images/alert.jpg") %>";

setCookie('MWN_ALERT_ICON', '0', 1);

} catch (e) {

//ignore

}

}



//function to handleAlert from listener app

// handleAlert must exist to receive communications from the
alerting listener client

// the 'msg' argument carries the test message of the alert

function handleAlert(type,priority,msg,id)

{

// all parameters ignored at this time

// change below to the icon that would notify of a new alert

alertRecdIcon();

}



// functions to set and get cookies -- used for alert icon state

function setCookie(c_name,value,expiredays)

{

var exdate=new Date();

exdate.setDate(exdate.getDate()+expiredays);

expiredays = null;

document.cookie=c_name+ "=" +escape(value)+"; path=/;
domain=xyz.com;"+

((expiredays==null) ? "" : ";expires="+exdate.toGMTString());

}



function getCookie(c_name)

{

if (document.cookie.length>0)

{

c_start=document.cookie.indexOf(c_name + "=");

if (c_start!=-1)

{

c_start=c_start + c_name.length+1;

c_end=document.cookie.indexOf(";",c_start);

if (c_end==-1) c_end=document.cookie.length;

return unescape(document.cookie.substring(c_start,c_end));

}

}

return "";

}



</script>



<div id="MobileScreen" class="mobileScreen">

<form id="form1" runat="server">



<input type="hidden" value="" name="txtScannedData"
id="txtScannedData" runat="server" />

<input type="hidden" value="" name="txtBarcodeType"
id="txtBarcodeType" runat="server" />

<input type="hidden" value="K" name="txtInputType"
id="txtInputType" runat="server" />



<div id="GlobalNavBar"
class="absGlobalNav">

<asp:ContentPlaceHolder ID="GlobalNavBarArea"
runat="server">

<div id="globalNavSect">

<input type="image"
name="element1" src="<%= Page.ResolveUrl("~/Images/red1px.gif") %>"
onclick="return false;"/>

<asp:ImageButton
ID="GlobalNavHome" runat="server" AlternateText="Home"
CssClass="globalNavBtn1" ImageUrl="~/Images/home.jpg" Visible="false"
OnClick="GlobalNavBarHome_Click" />


<asp:ImageButton ID="GlobalNavScan" runat="server" AlternateText="Scan"
CssClass="globalNavBtn2" ImageUrl="~/Images/scan.jpg" Visible="false"
OnClick="GlobalNavBarScan_Click" />


<asp:ImageButton ID="GlobalNavToggle" runat="server"
AlternateText="Toggle" CssClass="globalNavBtn2"
ImageUrl="~/Images/toggle.jpg" Visible="false"
OnClick="GlobalNavBarToggle_Click" />


<asp:ImageButton ID="GlobalNavAlerts" runat="server"
AlternateText="Alerts" CssClass="globalNavBtn3"
ImageUrl="~/Images/alert.jpg" Visible="true"
OnClientClick="alertNormalIcon();" OnClick="GlobalNavBarAlerts_Click" />


<asp:ImageButton ID="GlobalNavInfo" runat="server" AlternateText="Info"
CssClass="globalNavBtn3" ImageUrl="~/Images/info.jpg" Visible="false"
OnClick="GlobalNavBarInfo_Click" />


<asp:ImageButton ID="GlobalNavExit" runat="server" AlternateText="Exit"
CssClass="globalNavBtn4" ImageUrl="~/Images/exit.jpg" Visible="false"
OnClick="GlobalNavBarExit_Click" />


<asp:ImageButton ID="GlobalNavKeyboard" runat="server"
AlternateText="Keyboard" CssClass="globalNavBtn4"
ImageUrl="~/Images/key.jpg" Visible="false"
OnClientClick="setFocusTxt();sip_show();return false;" />


<asp:ImageButton ID="GlobalNavChangeView" runat="server"
AlternateText="Change View" CssClass="globalNavBtn4"
ImageUrl="~/Images/change_view.jpg" Visible="false"
OnClick="GlobalNavBarChangeView_Click" />

</div>

</asp:ContentPlaceHolder>

</div>

<div id="WaitScreen"
class="absContentArea" style='display: none'>

<table border="0" width="100%">

<tr align="center">

<td align="center">

<asp:Image
ID="ProgressImage" ImageAlign="absmiddle" ImageUrl="~/Images/progress.gif"
AlternateText="In Progress" runat="server"/>

<!--img
id="ProgressImage" align=absmiddle src="/Images/progress.gif" alt="In
Progress" /-->

</td>

</tr>

<tr align="center"
valign="top">

<td align="center"
valign="top">

<font face="Tahoma"
style="font-weight:bold" size="3"><%= BusyMessage %></font>

<% if
(this.DisplayTimer) { %>

<br /><br />

<span id="time"
class="waitTimer">

&nbsp;&nbsp;

</span>

<% } %>

</td>

</tr>

</table>

</div>

<div id="Content"
class="absContentArea">

<asp:ContentPlaceHolder ID="ContentArea" runat="server" >

<h3>Default Content</h3>

</asp:ContentPlaceHolder>

</div>

<div id="AppNavBar" class="appNav">

<asp:ContentPlaceHolder ID="AppNavBarArea" runat="server">

<div id="appNavSect">

<asp:ImageButton ID="AppNavBarBack" runat="server"
AlternateText="Back" CssClass="appNavBtn1" ImageUrl="~/Images/Back.jpg"
Visible="false" OnClick="AppNavBarBack_Click" />

<asp:ImageButton ID="AppNavBarUp" runat="server"
AlternateText="Up" CssClass="appNavBtn2" ImageUrl="~/Images/up.jpg"
Visible="false" OnClick="AppNavBarUp_Click" />

<asp:ImageButton ID="AppNavBarDown" runat="server"
AlternateText="Down" CssClass="appNavBtn3" ImageUrl="~/Images/down.jpg"
Visible="false" OnClick="AppNavBarDown_Click" />

<asp:ImageButton ID="AppNavBarNext" runat="server"
AlternateText="Next" CssClass="appNavBtn4" ImageUrl="~/Images/next.jpg"
Visible="false" OnClick="AppNavBarNext_Click" />

<asp:ImageButton ID="AppNavBarGo" runat="server"
AlternateText="Go" CssClass="appNavBtn4" ImageUrl="~/Images/go.gif"
Visible="false" OnClick="AppNavBarGo_Click" />

</div>

</asp:ContentPlaceHolder>

<div class="ScreenID"><asp:Label ID="lblScreenID"
runat="server"></asp:Label></div>

</div>

</form>



<script language="javascript" type="text/javascript">

var theForm = document.forms['aspnetForm'];

if (!theForm) {

theForm = document.aspnetForm;

}

</script>



</div>

<script type="text/javascript" language="javascript">

disableSelection(document.getElementById("MobileScreen"));



//set alert icon based on cookie

if (getCookie('MWN_ALERT_ICON')=='1') {

alertRecdIcon();

} else {

alertNormalIcon();

}

</script>

</body>

</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top