By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,450 Members | 923 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,450 IT Pros & Developers. It's quick & easy.

Java script memory leak

P: n/a
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:onscan('%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.displa y ="block";

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

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

document.getElementById('globalNavSect').style.dis play ="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","code 128");

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

external.CETerm.setProperty("session"+sessIdx+".sc anner."+allSymbologies[i]+".enabled",false);

}

// Enable the required symbologies

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

external.CETerm.setProperty("session"+sessIdx+".sc anner."+symbologies[i]+".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_Gl obalNavAlerts').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_Gl obalNavAlerts').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("MobileSc reen"));

//set alert icon based on cookie

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

alertRecdIcon();

} else {

alertNormalIcon();

}

</script>

</body>

</html>
Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies

P: n/a
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/200...ory-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
JI have a web app running on the windows CE device. In one of the
Jasp.net
Jpages - it has javascript code. That seems to have a memory leak.
JWhen I run the web app - in about one hour, the app hangs. I looked
Jat the
Jmemory and it seems to be full.
JI removed all the javascript code - and the app seems to be have no
Jleaks.
JAs soon as I include my javascript code - the memory consumption
Jgradually
Jincreases.
JWhether I actually invoke the javascript code or not - it doesn't
Jmatter.
JThe memory leak happens.
JI have been looking at some of the discussions around memory leak and
Jthey
Jtalk about circular references and closures.
JWell, I dont think I have that issue.
JWhat else can be the problem?
JHere is the page that has the problem:
J>
J<%@ Master Language="C#" AutoEventWireup="true" Inherits="MyMobile"
JCodeBehind="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"
Jcontent="javascript:onscan('%s','%s','%s','%s','% s');" />
J>
J</head>
J>
J<body onload="OnLoad()" onbeforeunload="showProgress();"
Jonunload="sip_hide();" onkeydown="cancelBack();">
J>
J<% if (this.DisplayProgress && this.DisplayTimer)
J>
J{ %>
J>
J<script language="javascript" type="text/javascript" src="<%=
JPage.ResolveUrl("~/Scripts/waitTimer.js") %>">
J>
J</script>
J>
J<% } %>
J>
J<script language="javascript" type="text/javascript" src="<%=
JPage.ResolveUrl("~/Scripts/button.js") %>"></script>
J>
J<script language="javascript" type="text/javascript">
J>
Jvar sipState = false;
J>
Jvar isSubmitting = false; // limits page to only one Scan or
JEnter keypress, used by onkeydown method, injected via Basepage,
JHandleEnterKey(...)
J>
Jfunction sip_hide()
J>
J{
J>
J// check if CE device
J>
Jif (navigator.appVersion.indexOf("Windows CE") >= 0)
J>
J{
J>
Jexternal.CETerm.PostIDA( "IDA_SIP_HIDE", 0 );
J>
J}
J>
J}
J>
Jfunction sip_show()
J>
J{
J>
J// check if CE device
J>
Jif (navigator.appVersion.indexOf("Windows CE") >= 0)
J>
J{
J>
Jexternal.CETerm.PostIDA( "IDA_SIP_SHOW", 0 );
J>
Jreturn false;
J>
J}
J>
Jreturn false;
J>
J}
J>
Jfunction sip_toggle()
J>
J{
J>
Jif (sipState == false)
J>
J{
J>
Jexternal.CETerm.PostIDA( "IDA_SIP_SHOW", 0 );
J>
JsipState = true;
J>
Jreturn false;
J>
J}
J>
Jelse
J>
J{
J>
Jexternal.CETerm.PostIDA( "IDA_SIP_HIDE", 0 );
J>
JsipState = false;
J>
J}
J>
J}
J>
Jfunction 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>
Jvar bDisplayTimer = false;
J>
J<% if (this.DisplayTimer) { %>
J>
JbDisplayTimer = true;
J>
J<% } %>
J>
JdisplayBusyPage(bDisplayTimer);
J>
J<% } %>
J>
J}
J>
Jfunction displayBusyPage(bTimerNeeded)
J>
J{
J>
JsetTimeout('document.images["<%= ProgressImage.ClientID
J%>"].src="<%= Page.ResolveUrl("~/Images/progress.gif") %>"', 200);
J>
Jif (bTimerNeeded)
J>
JsetTimeout("StartTimer()",10);
J>
Jdocument.getElementById('WaitScreen').style.displ ay
J="block";
J>
Jdocument.getElementById('Content').style.display ="none";
J>
Jdocument.getElementById('appNavSect').style.displ ay
J="none";
J>
Jdocument.getElementById('globalNavSect').style.di splay
J="none";
J>
J}
J>
J// Scan Capture event
J>
Jfunction baseScanEvent(data,source,type,time, length)
J>
J{
J>
Jif (!isSubmitting) {
J>
JtheForm.<%= txtScannedData.ClientID %>.value = data;
J>
JisSubmitting = true;
J>
Jexternal.CETerm.PostIDA( "IDA_SCAN_SUSPEND", 0 );
J//turn off scanner, user experience, limit to one scan per submit
J>
JtheForm.submit();
J>
J}
J>
J}
J>
Jvar onScanEvent = function scanEvent(data,source,type,time,
Jlength) {
J>
JbaseScanEvent(data,source,type,time,
Jlength);
J>
J}
J>
Jfunction onscan(data, source, type, time, length)
J>
J{
J>
J// external.CETerm.PostIDA( "IDA_SCAN_SUSPEND", 0 );
J>
Jvar inputTypeElem = document.getElementById('<%=
JtxtInputType.ClientID %>');
J>
JinputTypeElem.value = 'S';
J>
Jvar barcodeTypeElem = document.getElementById('<%=
JtxtBarcodeType.ClientID %>');
J>
Jvar btArray = source.split(':');
J>
Jif (btArray.length 1)
J>
JbarcodeTypeElem.value = btArray[1];
J>
JonScanEvent(data,source,type,time,length);
J>
J}
J>
J// End Scan Capture event
J>
J// base Screen Load event - offers beep functionality
J>
Jfunction baseLoadEvent()
J>
J{
J>
Jtry
J>
J{
J>
J// For Beep(s) on Windows CE
J>
Jif (navigator.appVersion.indexOf("Windows CE") >= 0)
J>
J{
J>
Jvar count = <%= BeepCount %>;
J>
Jfor(var i=1; i <= count; i++)
J>
J{
J>
J<%= BeepSoundPlayString %>
J>
Jfor(var j=1; j<=100000; j++);
J>
J}
J>
J}
J>
J}
J>
Jcatch (e)
J>
J{
J>
Jalert(e.message);
J>
J}
J>
J}
J>
Jvar onLoadEvent = function loadEvent() {
J>
JbaseLoadEvent();
J>
J}
J>
J//End screen OnLoad event
J>
J// Scan Config event
J>
Jfunction baseScanConfigEvent()
J>
J{
J>
Jtry
J>
J{
J>
J// First Beep on Windows CE
J>
Jif (navigator.appVersion.indexOf("Windows CE") >= 0)
J>
J{
J>
Jvar sessIdx = external.sessionindex;
J>
J//check for any enabled symbologies
J>
Jvar enabledSymbologies = "<%=
Jthis.EnabledSymbologies %>";
J>
Jif (external.CETerm.ActiveSession == 3) {
J>
Jif (enabledSymbologies == '')
J{
J>
Jexternal.CETerm.PostIDA(
J"IDA_SCAN_SUSPEND", 0 );
J>
Jreturn;
J>
J} else {
J>
Jexternal.CETerm.PostIDA(
J"IDA_SCAN_RESUME", 0 );
J>
J}
J>
J}
J>
Jvar symbologies =
JenabledSymbologies.split(",");
J>
J// Disable all the common symbologies
J>
Jvar allSymbologies = new
JArray("upca","upce0","ean8","ean13","code39","cod e128");
J>
Jfor (var i=0; i < allSymbologies.length; i++) {
J>
J>
Jexternal.CETerm.setProperty("session"+sessIdx+".s canner."+allSymbolog
Jies[i]+".enabled",false);
J>
J}
J>
J// Enable the required
Jsymbologies
J>
Jfor (var i=0; i < symbologies.length; i++) {
J>
J>
Jexternal.CETerm.setProperty("session"+sessIdx+".s canner."+symbologies
J[i]+".enabled",true);
J>
J}
J>
J// Set the beeptime
J>
Jvar beepTime = <%= BeepTime %>;
J>
Jexternal.CETerm.setProperty("session" + sessIdx +
J".scanner.decodebeeptime", beepTime);
J>
J// Apply the settings
J>
Jexternal.CETerm.PostIDA(
J"IDA_SCAN_APPLYCONFIG", 0 );
J>
J}
J>
J}
J>
Jcatch (e)
J>
J{
J>
Jalert(e.message);
J>
J}
J>
J}
J>
Jvar onScanConfig = function scanConfigEvent() {
J>
JbaseScanConfigEvent();
J>
J}
J>
J// End Scan Config event
J>
Jfunction OnLoad()
J>
J{
J>
JonLoadEvent();
J>
JonScanConfig();
J>
J}
J>
Jfunction disableSelection(target) {
J>
Jtarget.onselectstart=function() {return false}
J>
J}
J>
Jfunction cancelBack()
J>
J{
J>
Jif ((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 ||
Jevent.srcElement.isTextEdit == false)
J>
J)
J>
J{
J>
Jevent.cancelBubble = true;
J>
Jevent.returnValue = false;
J>
J}
J>
J}
J>
J//function to toggle alert icon to "active" status
J>
Jfunction alertRecdIcon () {
J>
Jtry {
J>
J>
Jdocument.getElementById('ctl00_GlobalNavBarArea_G lobalNavAlerts').src
J="<%= Page.ResolveUrl("~/Images/new_alert_received.gif") %>";
J>
JsetCookie('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>
Jfunction alertNormalIcon() {
J>
Jtry {
J>
J>
Jdocument.getElementById('ctl00_GlobalNavBarArea_G lobalNavAlerts').src
J="<%= Page.ResolveUrl("~/Images/alert.jpg") %>";
J>
JsetCookie('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
Jalerting listener client
J>
J// the 'msg' argument carries the test message of the alert
J>
Jfunction 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
Jalert
J>
JalertRecdIcon();
J>
J}
J>
J// functions to set and get cookies -- used for alert icon
Jstate
J>
Jfunction setCookie(c_name,value,expiredays)
J>
J{
J>
Jvar exdate=new Date();
J>
Jexdate.setDate(exdate.getDate()+expiredays);
J>
Jexpiredays = null;
J>
Jdocument.cookie=c_name+ "=" +escape(value)+"; path=/;
Jdomain=xyz.com;"+
J>
J((expiredays==null) ? "" :
J";expires="+exdate.toGMTString());
J>
J}
J>
Jfunction getCookie(c_name)
J>
J{
J>
Jif (document.cookie.length>0)
J>
J{
J>
Jc_start=document.cookie.indexOf(c_name + "=");
J>
Jif (c_start!=-1)
J>
J{
J>
Jc_start=c_start + c_name.length+1;
J>
Jc_end=document.cookie.indexOf(";",c_start);
J>
Jif (c_end==-1) c_end=document.cookie.length;
J>
Jreturn
Junescape(document.cookie.substring(c_start,c_end) );
J>
J}
J>
J}
J>
Jreturn "";
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"
Jid="txtScannedData" runat="server" />
J>
J<input type="hidden" value="" name="txtBarcodeType"
Jid="txtBarcodeType" runat="server" />
J>
J<input type="hidden" value="K" name="txtInputType"
Jid="txtInputType" runat="server" />
J>
J<div id="GlobalNavBar"
Jclass="absGlobalNav">
J>
J<asp:ContentPlaceHolder ID="GlobalNavBarArea"
Jrunat="server">
J>
J<div id="globalNavSect">
J>
J<input
Jtype="image" name="element1" src="<%=
JPage.ResolveUrl("~/Images/red1px.gif") %>" onclick="return false;"/>
J>
J<asp:ImageButton
JID="GlobalNavHome" runat="server" AlternateText="Home"
JCssClass="globalNavBtn1" ImageUrl="~/Images/home.jpg" Visible="false"
JOnClick="GlobalNavBarHome_Click" />
J>
J>
J<asp:ImageButton ID="GlobalNavScan" runat="server"
JAlternateText="Scan" CssClass="globalNavBtn2"
JImageUrl="~/Images/scan.jpg" Visible="false"
JOnClick="GlobalNavBarScan_Click" />
J>
J>
J<asp:ImageButton ID="GlobalNavToggle" runat="server"
JAlternateText="Toggle" CssClass="globalNavBtn2"
JImageUrl="~/Images/toggle.jpg" Visible="false"
JOnClick="GlobalNavBarToggle_Click" />
J>
J>
J<asp:ImageButton ID="GlobalNavAlerts" runat="server"
JAlternateText="Alerts" CssClass="globalNavBtn3"
JImageUrl="~/Images/alert.jpg" Visible="true"
JOnClientClick="alertNormalIcon();" OnClick="GlobalNavBarAlerts_Click"
J/>
J>
J>
J<asp:ImageButton ID="GlobalNavInfo" runat="server"
JAlternateText="Info" CssClass="globalNavBtn3"
JImageUrl="~/Images/info.jpg" Visible="false"
JOnClick="GlobalNavBarInfo_Click" />
J>
J>
J<asp:ImageButton ID="GlobalNavExit" runat="server"
JAlternateText="Exit" CssClass="globalNavBtn4"
JImageUrl="~/Images/exit.jpg" Visible="false"
JOnClick="GlobalNavBarExit_Click" />
J>
J>
J<asp:ImageButton ID="GlobalNavKeyboard" runat="server"
JAlternateText="Keyboard" CssClass="globalNavBtn4"
JImageUrl="~/Images/key.jpg" Visible="false"
JOnClientClick="setFocusTxt();sip_show();return false;" />
J>
J>
J<asp:ImageButton ID="GlobalNavChangeView" runat="server"
JAlternateText="Change View" CssClass="globalNavBtn4"
JImageUrl="~/Images/change_view.jpg" Visible="false"
JOnClick="GlobalNavBarChangeView_Click" />
J>
J</div>
J>
J</asp:ContentPlaceHolder>
J>
J</div>
J>
J<div id="WaitScreen"
Jclass="absContentArea" style='display: none'>
J>
J<table border="0"
Jwidth="100%">
J>
J<tr align="center">
J>
J<td align="center">
J>
J<asp:Image
JID="ProgressImage" ImageAlign="absmiddle"
JImageUrl="~/Images/progress.gif" AlternateText="In Progress"
Jrunat="server"/>
J>
J<!--img
Jid="ProgressImage" align=absmiddle src="/Images/progress.gif" alt="In
JProgress" /-->
J>
J</td>
J>
J</tr>
J>
J<tr align="center"
Jvalign="top">
J>
J<td align="center"
Jvalign="top">
J>
J<font
Jface="Tahoma" style="font-weight:bold" size="3"><%= BusyMessage
J%></font>
J>
J<% if
J(this.DisplayTimer) { %>
J>
J<br /><br />
J>
J<span
Jid="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"
Jclass="absContentArea">
J>
J<asp:ContentPlaceHolder ID="ContentArea"
Jrunat="server" >
J>
J<h3>Default Content</h3>
J>
J</asp:ContentPlaceHolder>
J>
J</div>
J>
J<div id="AppNavBar"
Jclass="appNav">
J>
J<asp:ContentPlaceHolder ID="AppNavBarArea"
Jrunat="server">
J>
J<div id="appNavSect">
J>
J<asp:ImageButton ID="AppNavBarBack"
Jrunat="server" AlternateText="Back" CssClass="appNavBtn1"
JImageUrl="~/Images/Back.jpg" Visible="false"
JOnClick="AppNavBarBack_Click" />
J>
J<asp:ImageButton ID="AppNavBarUp" runat="server"
JAlternateText="Up" CssClass="appNavBtn2" ImageUrl="~/Images/up.jpg"
JVisible="false" OnClick="AppNavBarUp_Click" />
J>
J<asp:ImageButton ID="AppNavBarDown"
Jrunat="server" AlternateText="Down" CssClass="appNavBtn3"
JImageUrl="~/Images/down.jpg" Visible="false"
JOnClick="AppNavBarDown_Click" />
J>
J<asp:ImageButton ID="AppNavBarNext"
Jrunat="server" AlternateText="Next" CssClass="appNavBtn4"
JImageUrl="~/Images/next.jpg" Visible="false"
JOnClick="AppNavBarNext_Click" />
J>
J<asp:ImageButton ID="AppNavBarGo" runat="server"
JAlternateText="Go" CssClass="appNavBtn4" ImageUrl="~/Images/go.gif"
JVisible="false" OnClick="AppNavBarGo_Click" />
J>
J</div>
J>
J</asp:ContentPlaceHolder>
J>
J<div class="ScreenID"><asp:Label ID="lblScreenID"
Jrunat="server"></asp:Label></div>
J>
J</div>
J>
J</form>
J>
J<script language="javascript"
Jtype="text/javascript">
J>
Jvar theForm = document.forms['aspnetForm'];
J>
Jif (!theForm) {
J>
JtheForm = document.aspnetForm;
J>
J}
J>
J</script>
J>
J</div>
J>
J<script type="text/javascript" language="javascript">
J>
JdisableSelection(document.getElementById("MobileS creen"));
J>
J//set alert icon based on cookie
J>
Jif (getCookie('MWN_ALERT_ICON')=='1') {
J>
JalertRecdIcon();
J>
J} else {
J>
JalertNormalIcon();
J>
J}
J>
J</script>
J>
J</body>
J>
J</html>
J>
Jun 27 '08 #2

P: n/a
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" <ja*@microsoft.comwrote in message
news:#P**************@TK2MSFTNGP04.phx.gbl...
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:onscan('%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.displa y ="block";

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

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

document.getElementById('globalNavSect').style.dis play ="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","code 128");

for (var i=0; i < allSymbologies.length; i++) {
external.CETerm.setProperty("session"+sessIdx+".sc anner."+allSymbologies[i]+".enabled",false);

}

// Enable the required symbologies

for (var i=0; i < symbologies.length; i++) {
external.CETerm.setProperty("session"+sessIdx+".sc anner."+symbologies[i]+".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_Gl obalNavAlerts').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_Gl obalNavAlerts').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("MobileSc reen"));

//set alert icon based on cookie

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

alertRecdIcon();

} else {

alertNormalIcon();

}

</script>

</body>

</html>

Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.