-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #344 from canjs/cc-leak
Prevent leak caused by connectedCallback setup code
- Loading branch information
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<title>Memory tests</title> | ||
<style> | ||
body { | ||
font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | ||
} | ||
|
||
button { | ||
font-size: 200%; | ||
background: salmon; | ||
border: 2px solid black; | ||
color: black; | ||
padding: .5em 1em; | ||
cursor: pointer; | ||
} | ||
|
||
#runner { | ||
text-align: center; | ||
} | ||
</style> | ||
<h1>connectedCallback memory leak</h1> | ||
<p>This tests a leak in using ViewModel#connectedCallback when the element is never inserted into the page. Use the devtools memory tool and click <strong>run me</strong>. Every time you click run a new component is created. Hopefully there are no leaks.</p> | ||
<div id="runner"> | ||
<button type="button">Run me</button> | ||
</div> | ||
<div id="root"></div> | ||
<script src="../node_modules/steal/steal.js"></script> | ||
<script type="steal-module"> | ||
var Component = require("can-component"); | ||
var nodeLists = require("can-view-nodelist"); | ||
|
||
var MyComponent = Component.extend({ | ||
tag: "my-thing", | ||
view: "Hello world", | ||
ViewModel: { | ||
// Any connectedCallback will do, just the existence causes a leak. | ||
connectedCallback: function(){} | ||
} | ||
}); | ||
|
||
function run() { | ||
var inst = new MyComponent(); | ||
nodeLists.unregister(inst.nodeList); | ||
} | ||
|
||
document.querySelector('button').addEventListener('click', run); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters