source: Dev/trunk/src/client/dojo/tests/_base/connectLeaks.html

Last change on this file was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 2.7 KB
Line 
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
4<script type="text/javascript" src="../../dojo.js"></script>
5
6<script type="text/javascript">
7
8        var w, start;
9        dojo.addOnLoad(function(){
10                 w = dojo.byId('ipt');
11        });
12
13        function repeat(/*String*/ testName, /*Function*/ func, /*Number*/ iters, /*Date?*/ start){
14                // summary:
15                //              Call func() for iters times
16
17                start = start || new Date();
18
19                while(iters-- > 0){
20                        func();
21                        if(iters % 1000 == 0){
22                                // avoid locking up browser or getting "script hung" warning dialog
23                                dojo.byId("log").innerHTML = "Running " + testName + " (" + iters + ")";
24                                setTimeout(function(){ repeat(testName, func, iters, start)}, 0);
25                                return;
26                        }
27                }
28                if(typeof CollectGarbage != "undefined"){
29                        CollectGarbage(); // collect garbage in IE to make it easy to read the memory levels
30                }
31                dojo.byId("log").innerHTML = "Finished " + testName + ", elapsed time = " + ((new Date()) - start)/1000 + "s";
32        }
33
34        var cc = [];
35        function disconnectTest(){
36                //console.log("repeating");             
37                dojo.forEach(cc, function(c, i, conns){
38                        dojo.disconnect(c);
39                });
40                cc = [
41                        dojo.connect(w, "onblur", func),
42                        dojo.connect(w, "onclick", func),
43                        dojo.connect(w, "onchange",func)
44                ];
45        }
46
47        function func(){
48                console.log('callback triggered')
49        }
50        function destroyTest(){
51                var button = dojo.place("<button>test button</button>", dojo.body());
52                dojo.connect(button, "onclick", func);
53                dojo.destroy(button);
54        }
55        function removeTest(){
56                var button = dojo.place("<button>test button</button>", dojo.body());
57                dojo.connect(button, "onclick", func);
58                button.parentNode.removeChild(button);
59        }
60        function iframeTest(){
61                var iframe = dojo.place("<iframe style='display:none' src='connectLeaks.html?inframe'></iframe>", dojo.body());
62                setTimeout(function(){
63                        dojo.destroy(iframe);
64                }, 1000);
65        }
66        if(location.search == "?inframe"){
67       
68                dojo.ready(function(){
69                        var a  = [];
70                        for(var i = 0; i < 100000;i++){
71                                a.push({a:4});
72                        }
73                        dojo.connect(document.body, "unload", function(){
74                                a.push(4);
75                                parent.console.log("a " + a.length);
76                        });
77                });
78        }
79</script>
80</head>
81
82<body class="tundra">
83        <h1>Memory leak tests</h1>
84        <p>Monitor memory usage in IE6/7 (or any browser) before/after pressing buttons below</p>
85        <button onclick="repeat('disconnect test', disconnectTest, 10000);">dojo.disconnect() test</button>
86        <button onclick="repeat('destroy test', destroyTest, 10000);">dojo.destroy() test</button>
87        <button onclick="repeat('remove test', removeTest, 10000);">remove node test</button>
88        <button onclick="repeat('iframe test', iframeTest, 10);">iframe test</button>
89        <button onclick="CollectGarbage()">Collect Garbage</button>
90        <div id="log"></div>
91        <input id='ipt' value='connect target' type=button />
92</body>
93</html>
Note: See TracBrowser for help on using the repository browser.