{"action":"created","issue":{"url":"https://api.github.com/repos/bitovi/canjs/issues/1666","labels_url":"https://api.github.com/repos/bitovi/canjs/issues/1666/labels{/name}","comments_url":"https://api.github.com/repos/bitovi/canjs/issues/1666/comments","events_url":"https://api.github.com/repos/bitovi/canjs/issues/1666/events","html_url":"https://github.com/bitovi/canjs/issues/1666","id":72533896,"number":1666,"title":"Possible memory leak with observable in template","user":{"login":"dylanrtt","id":11302736,"avatar_url":"https://avatars.githubusercontent.com/u/11302736?v=3","gravatar_id":"","url":"https://api.github.com/users/dylanrtt","html_url":"https://github.com/dylanrtt","followers_url":"https://api.github.com/users/dylanrtt/followers","following_url":"https://api.github.com/users/dylanrtt/following{/other_user}","gists_url":"https://api.github.com/users/dylanrtt/gists{/gist_id}","starred_url":"https://api.github.com/users/dylanrtt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dylanrtt/subscriptions","organizations_url":"https://api.github.com/users/dylanrtt/orgs","repos_url":"https://api.github.com/users/dylanrtt/repos","events_url":"https://api.github.com/users/dylanrtt/events{/privacy}","received_events_url":"https://api.github.com/users/dylanrtt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"moschel","id":22180,"avatar_url":"https://avatars.githubusercontent.com/u/22180?v=3","gravatar_id":"","url":"https://api.github.com/users/moschel","html_url":"https://github.com/moschel","followers_url":"https://api.github.com/users/moschel/followers","following_url":"https://api.github.com/users/moschel/following{/other_user}","gists_url":"https://api.github.com/users/moschel/gists{/gist_id}","starred_url":"https://api.github.com/users/moschel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/moschel/subscriptions","organizations_url":"https://api.github.com/users/moschel/orgs","repos_url":"https://api.github.com/users/moschel/repos","events_url":"https://api.github.com/users/moschel/events{/privacy}","received_events_url":"https://api.github.com/users/moschel/received_events","type":"User","site_admin":false},"milestone":null,"comments":7,"created_at":"2015-05-01T21:59:51Z","updated_at":"2015-07-08T14:28:22Z","closed_at":null,"body":"In the process of trying to narrow down the cause of an apparent memory leak in my app, I came across something strange as a result of rendering a stache template with an observable (can.Map).\r\n\r\nSimplified version (just a can.Map):\r\nhttp://jsbin.com/vavecuyaxi/1/edit?js,console,output\r\n\r\nOriginal version (using can.Model with model store):\r\nhttp://jsbin.com/rewiwiritu/1/edit?js,console,output\r\n\r\nClick the create button then the destroy button, then repeat a couple times. You can see the _bindings count (and the __bindEvents.name array) on the person keeps increasing. If it were to go back to 0 in the second example, the model would be removed from the store at some point, but that never happens.\r\n\r\nIf you use a ```new can.Map``` each time instead of the existing one, there does not appear to be a leak, probably because the object is being garbage collected along with its events. However, that does leak in mustache. To see that in action, just run the following code in your debugger while recording memory usage.\r\n\r\n```\r\nsetInterval(function () {\r\n    can.mustache('{{ name }}')(new can.Map({name: 'Bob'}));\r\n}, 100);\r\n```"},"comment":{"url":"https://api.github.com/repos/bitovi/canjs/issues/comments/119596902","html_url":"https://github.com/bitovi/canjs/issues/1666#issuecomment-119596902","issue_url":"https://api.github.com/repos/bitovi/canjs/issues/1666","id":119596902,"user":{"login":"justinbmeyer","id":78602,"avatar_url":"https://avatars.githubusercontent.com/u/78602?v=3","gravatar_id":"","url":"https://api.github.com/users/justinbmeyer","html_url":"https://github.com/justinbmeyer","followers_url":"https://api.github.com/users/justinbmeyer/followers","following_url":"https://api.github.com/users/justinbmeyer/following{/other_user}","gists_url":"https://api.github.com/users/justinbmeyer/gists{/gist_id}","starred_url":"https://api.github.com/users/justinbmeyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinbmeyer/subscriptions","organizations_url":"https://api.github.com/users/justinbmeyer/orgs","repos_url":"https://api.github.com/users/justinbmeyer/repos","events_url":"https://api.github.com/users/justinbmeyer/events{/privacy}","received_events_url":"https://api.github.com/users/justinbmeyer/received_events","type":"User","site_admin":false},"created_at":"2015-07-08T14:28:22Z","updated_at":"2015-07-08T14:28:22Z","body":"This doesn't look like it is ever appending the   Fragment after the first time. This is because there are no divs to append it to. \n\nIf that is the case, Stache will leak, but this isn't a valid use case. \n\nSent from my iPhone\n\n> On Jul 8, 2015, at 7:50 AM, Guido Smeets <notifications@github.com> wrote:\n> \n> This seems to leak even if I use a wrapping element:\n> \n> <script src=\"/Scripts/1.0.0.0/lib/jquery/jquery-1.11.2.js\"></script>\n> <script src=\"/Scripts/1.0.0.0/lib/can.debug.min.js\"></script>\n> \n> \n> <script>\n> \n>     var template = can.stache( \"<p>{{test}}</p>\" );\n>     var foo = false;\n> \n>     $( document ).click( function() {\n>         if ( foo ) {\n>             $( \"div\" ).remove();\n>         } else {\n>             var fragment = template({ test: \"test2\" });\n>             $( \"div\" ).append( fragment );\n>             foo = true;\n>         }\n>     });\n> \n> </script>\n> Using the 3 snapshot technique:\n> \n> First snapshot after load.\n> Click the screen,\n> Snapshot\n> Click the screen\n> \n> \n> If I change can.stache into can.mustache and repeat the procedure I don't get those dom nodes floating about.\n> \n> —\n> Reply to this email directly or view it on GitHub.\n> \n"}}