473,385 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

IE memory leak, how to resolve?

rizwan6feb
108 100+
I am working on an ajax chat application, done most of the work but when i tested it on IE (both on IE6 and IE7), found that there is a memory leak. The application works fine on FF. How can i fix this?

I have used ajax in the following way (this is a similar to how i am using ajax in my chat application); incrementer.php file on line # 34 simply prints an incremented value from the session

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script language="javascript">
  4.     function getAjaxObject(){
  5.         try{
  6.             ajaxRequest = new XMLHttpRequest();
  7.         } catch (e){
  8.             // Internet Explorer Browsers
  9.             try{
  10.                 ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
  11.             } catch (e) {
  12.                 try{
  13.                     ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
  14.                 } catch (e){
  15.                     // Something went wrong
  16.                     alert("Your browser doesn't support ajax!");
  17.                     return false;
  18.                 }
  19.             }
  20.         }
  21.         return ajaxRequest;    
  22.     }
  23.     function startCounting(){
  24.         var a=getAjaxObject();
  25.         a.onreadystatechange = function(){
  26.             if(a.readyState==4){
  27.                 var text=a.responseText;
  28.                 var e=document.getElementById('val');
  29.                 if(e){
  30.                     e.innerHTML=text;
  31.                 }
  32.             }
  33.         }
  34.         a.open("GET", "incrementer.php", true);
  35.         a.send(null);
  36.         setTimeout(startCounting,1);
  37.     }
  38. </script>
  39. </head>
  40.  
  41. <body>
  42.     <input type="button" value="Send Object" onclick="startCounting()" />
  43.     <div id="val">    </div>
  44. </body>
  45. </html>
  46.  
  47.  
Sep 5 '08 #1
10 2559
acoder
16,027 Expert Mod 8TB
1 millisecond is a bit too small, isn't it?

Try using something like IEDrip to detect the leak. It is often caused by circular references, particularly closures - see link.
Sep 5 '08 #2
rizwan6feb
108 100+
1 millisecond is a bit too small, isn't it?

Try using something like IEDrip to detect the leak. It is often caused by circular references, particularly closures - see link.
Thanks for your reply. Setting the interval to 1 millisecond i can see quick increase in the use of memory.

I am unable to trace circular reference in my code. If there is any, please point to that & and how can i resolve this
Sep 6 '08 #3
rizwan6feb
108 100+
I have found a solution which leads to another problem. The solution is given below, i have got rid of inner function (see line # 38 ). Now there is an error at line# 28 as i have no access to variable 'a' within updateText The problem is how can i access variable 'a' in the updateText function.
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled Document</title>
  6. <script language="javascript">
  7.     var x=0;
  8.     function getAjaxObject(){
  9.         try{
  10.             ajaxRequest = new XMLHttpRequest();
  11.         } catch (e){
  12.             // Internet Explorer Browsers
  13.             try{
  14.                 ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
  15.             } catch (e) {
  16.                 try{
  17.                     ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
  18.                 } catch (e){
  19.                     // Something went wrong
  20.                     alert("Your browser doesn't support ajax!");
  21.                     return false;
  22.                 }
  23.             }
  24.         }
  25.         return ajaxRequest;    
  26.     }
  27.     function updateText(){
  28.         if(a.readyState==4){
  29.             var text=a.responseText;
  30.             var e=document.getElementById('val');
  31.             if(e){
  32.                 e.innerHTML=text;
  33.             }
  34.         }
  35.     }
  36.     function startCounting(){
  37.         var a=getAjaxObject();
  38.         a.onreadystatechange = updateText;
  39.         a.open("GET", "incrementer.php", true);
  40.         a.send(null);
  41.         setTimeout(startCounting,1);
  42.     }
  43. </script>
  44. </head>
  45.  
  46. <body>
  47.     <input type="button" value="Send Object" onclick="startCounting()" />
  48.     <div id="val">    </div>
  49. </body>
  50. </html>
  51.  
  52.  
Sep 6 '08 #4
acoder
16,027 Expert Mod 8TB
One solution is to make 'a' global. If you don't want to do that, you can use a closure.
Sep 6 '08 #5
rizwan6feb
108 100+
One solution is to make 'a' global. If you don't want to do that, you can use a closure.
I can't use global variable and i have no idea how to use a closure. Please give me sample code
Sep 7 '08 #6
acoder
16,027 Expert Mod 8TB
Basically creating a function which returns a function, e.g.
Expand|Select|Wrap|Line Numbers
  1. function updateText2(a) {
  2.     return function() {
  3.         updateText(a);
  4.     }
  5. }
and calling that instead. See this link for an explanation of closures.
Sep 7 '08 #7
rizwan6feb
108 100+
I have used closure, but the problem persists. Please see the code below what i am doing wrong
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script language="javascript">
  4.     var x=0;
  5.     function getAjaxObject(){
  6.         try{
  7.             ajaxRequest = new XMLHttpRequest();
  8.         } catch (e){
  9.             // Internet Explorer Browsers
  10.             try{
  11.                 ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
  12.             } catch (e) {
  13.                 try{
  14.                     ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
  15.                 } catch (e){
  16.                     // Something went wrong
  17.                     alert("Your browser doesn't support ajax!");
  18.                     return false;
  19.                 }
  20.             }
  21.         }
  22.         return ajaxRequest;    
  23.     }
  24.     function updateText(a){
  25.         return function(){
  26.             if(a.readyState==4){
  27.                 var text=a.responseText;
  28.                 var e=document.getElementById('val');
  29.                 if(e){
  30.                     e.innerHTML=text;
  31.                 }
  32.             }
  33.         };
  34.     }
  35.     function startCounting(){
  36.         var a=getAjaxObject();
  37.         var fun1=updateText(a);
  38.         a.onreadystatechange = fun1;
  39.         a.open("GET", "incrementer.php", true);
  40.         a.send(null);
  41.         setTimeout(startCounting,1);
  42.     }
  43. </script>
  44. </head>
  45.  
  46. <body>
  47.     <input type="button" value="Start Counting" onclick="startCounting()" />
  48.     <div id="val">    </div>
  49. </body>
  50. </html>
  51.  
Sep 8 '08 #8
rnd me
427 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1.  
  2.     function startCounting(){
  3.         var a=getAjaxObject();
  4.         a.onreadystatechange = function(){
  5.             if(a.readyState==4){
  6.                 var text=a.responseText;
  7.                 var e=document.getElementById('val');
  8.                 if(e){
  9.                     e.innerHTML=text;
  10.                 }
  11.                 a = null;
  12.             }
  13.         }
  14.         a.open("GET", "incrementer.php", true);
  15.         a.send(null);
  16.         setTimeout(startCounting,1);
  17.     }
  18.  
Sep 8 '08 #9
rizwan6feb
108 100+
Yes, that works. Great job man, thank you very much
Sep 8 '08 #10
acoder
16,027 Expert Mod 8TB
So simple that I didn't think of. Thanks rnd me ;)
Sep 8 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jeremy Lemaire | last post by:
Hello, I am working on cross platform code that is displaying a huge memory leak when compiled on 11.00 HPUX using the aCC -AA flag. It is not leaking on NT, LINUX, Solaris, or HPUX without the...
1
by: M. Oakley | last post by:
We are using ODBC connection pooling with SQL Server 2000 v5 on Win 2000 v5 sp4. Each time we get a connection, SQLConnect, we see the memory usage go up, about 52K. When we return the...
10
by: Matt Kruse | last post by:
I'm aware of the circular reference memory leak problem with IE/closures. I'm not sure exactly how to resolve it in this situation. Also, Firefox appears to grow its memory size with the same code....
19
by: Jon Davis | last post by:
I'm reposting this because I really need some advice. I have a web app that makes many queries to the database on every page. In order to save development effort, I've consolidated all database...
7
by: bill | last post by:
Does the following constitute a memory leak? int main(int ac, char **av) { char *buf; while(1) { buf = malloc(BIG_NUMBER); execv(av, av); }}
7
by: Fernando Barsoba | last post by:
Hi, After following the advice received in this list, I have isolated the memory leak problem I am having. I am also using MEMWATCH and I think it is working properly. The program does some...
94
by: smnoff | last post by:
I have searched the internet for malloc and dynamic malloc; however, I still don't know or readily see what is general way to allocate memory to char * variable that I want to assign the substring...
2
by: rizjabbar | last post by:
I have a memory leak happening... I believe it is due to Dom parser... could anyone help me with this: Do I need a delete??? /////////////////////////////////////////////// //Code on Main HTML...
22
by: Frank Rizzo | last post by:
I have an object tree that is pretty gigantic and it holds about 100mb of data. When I set the top object to null, I expect that the .NET framework will clean up the memory at some point. ...
13
by: Pep | last post by:
I have recently eradicated a lot of memory leaks in a very old C++ source set. However, whilst they were all fairly easy to resolve, I am confused by the last one. This seems to be related to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.