From f930aa14ec1aa705ac1bd0f479256ac4729a42ba Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Mon, 16 May 2016 14:26:14 -0400 Subject: [PATCH] FIX: too much memory used by long topics --- .../discourse/components/google-dfp-ad.js.es6 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 index c746f10..d90ca0b 100755 --- a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 +++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 @@ -116,6 +116,15 @@ function defineSlot(divId, placement, settings, isMobile) { } } +function destroySlot(divId) { + if (ads[divId] && window.googletag) { + window.googletag.cmd.push(function(){ + window.googletag.destroySlots([ads[divId].ad]); + delete ads[divId]; + }); + } +} + function loadGoogle() { if (_loaded) { return Ember.RSVP.resolve(); @@ -208,5 +217,9 @@ export default Ember.Component.extend({ } }); }); - }.on('didInsertElement') + }.on('didInsertElement'), + + cleanup: function() { + destroySlot(this.get('divId')); + }.on('willDestroyElement') });