forked from travis-hilterbrand/js-memory-leaks-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo-2.html
40 lines (36 loc) · 924 Bytes
/
demo-2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h4>Memory Leak Demo 2</h4>
<button onclick="action()">Action</button>
<script type="text/javascript">
function Item(x) {
this.x = x;
}
Item.prototype = {
clone: function() {
return new Item(this.x);
}
};
function action() {
for (var i = 0; i < data.length - 1; ++i) {
line = new Array(data[i].length);
for (var j = 0, l = data[i].length; j < l; ++j)
line[j] = data[i][j].clone();
for (var j = 0, l = data[i].length; j < l; ++j) {
data[i][j] = data[i + 1][j].clone();
data[i + 1][j] = line[j].clone();
}
}
}
var data = new Array(10);
for (var i = 0; i < data.length; ++i) {
data[i] = new Array(1000);
for (var j = 0, l = data[i].length; j < l; ++j)
data[i][j] = new Item(i * l + j);
}
</script>
</body>
</html>