From b5a364d3a24b4e69aaec2005e32649a494eed826 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Mon, 7 Jul 2014 21:03:39 +0800 Subject: [PATCH] try to fix memory leaks If the element is no longer in the DOM tree, stop its corresponding setInterval in the next cycle. --- jquery.timeago.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/jquery.timeago.js b/jquery.timeago.js index 483be57..ef9327a 100644 --- a/jquery.timeago.js +++ b/jquery.timeago.js @@ -175,6 +175,13 @@ }; function refresh() { + //check if it's still visible + if(!$.contains(document.documentElement,this)){ + //stop if it has been removed + $(this).timeago("dispose"); + return this; + } + var data = prepareData(this); var $s = $t.settings;