How to remove Twitter Embedded Timeline from a page completely to prevent memory leaks?


#1

Hi all,

I’ve been profiling my AngularJS application that contains an embedded timeline in one of the views. When the view gets destroyed so does the iframe and the script. However, it appears that the parent node of the iframe is stored in the retaining tree of the twitter object:

in HTMLElement @1110415 <-- Parent node of the script
targetEl in N @1122613 <-- Twitter widget
g in system / Context @761183
context in function() @1022431
[9] in Array @875739
2 in Window @827669

Since this state appears to be private, and there appears to be no “twttr.widgets.createTimeline.destroyTimeline” API to completely undo “twttr.widgets.createTimeline.createTimeline” ( see https://dev.twitter.com/docs/intents/events#factories), my application will continue to leak detached DOM nodes, as well as handlers.

Any workarounds? Any plans to support removal?

Thank you in advance,

Bob


#2

Hi Bob,

Thanks for letting us know about this. Probably no plan to provide explicit ‘destroy’ functions, but I’ll see if we can do an audit of the script to clean up element references better.

Ben


#3

Hi Ben,

Thanks for your prompt response. I’m curious to know how you would be able to know when to clean up the references if there wasn’t a way to specify that the component is no longer required. It looks as though the reference is closed over in the window resize timeout handler. This would need to be unbound to prevent the leak.

Cheers,

Bob


#4