Does jQuery .remove() clear out loaded javascript when it is used to remove a script tag?
<p>As the title says, if I remove a script tag from the DOM using:</p>

<pre><code>$('#scriptid').remove();
</code></pre>

<p>Does the javascript itself remain in memory or is it cleaned?</p>

<p>Or... am I completely misunderstanding the way in which browsers treat javascript?  Which is quite possible.</p>

<p>For those interested in my reason for asking see below:</p>

<p>I am moving some common javascript interactions from static script files into dynamically generated ones in PHP. Which are loaded on demand when a user requires them.</p>

<p>The reason for doing this is in order to move the logic serverside and and run a small script, returned from the server, clientside.  Rather than have a large script which contains a huge amount of logic, clientside.</p>

<p>This is a similar approach to what facebook does...</p>

<p><a href="http://blog.josemanuelperez.es/2011/01/talk-facebook-frontend-javascript/" rel="nofollow">Facebook talks frontend javascript</a></p>

<p>If we take a simple dialog for instance.  Rather than generating the html in javascript, appending it to the dom, then using jqueryUI's dialog widget to load it, I am now doing the following.</p>

<ul>
<li>Ajax request is made to dialog.php</li>
<li>Server generates html and javascript that is specific to this dialog then encodes them as JSON</li>
<li>JSON is returned to client.</li>
<li>HTML is appended to the <code>&lt;body&gt;</code> then once this is rendered, the javascript is also appended into the DOM.</li>
</ul>

<p>The javascript is executed automatically upon insertion and the dynamic dialog opens up.</p>

<p>Doing this has reduced the amount of javasript on my page dramatically however I am concerned about clean up of the inserted javascript.</p>

<p>Obviously once the dialog has been closed it is removed from the DOM using jQuery:</p>

<p><code>$('#dialog').remove();</code></p>

<p>The javascript is appended with an ID and I also remove this from the DOM via the same method.</p>

<p>However, as stated above, does using jQuery's .remove() actually clean out the javascript from memory or does it simple remove the <code>&lt;script&gt;</code> element from the DOM?</p>

<p>If so, is there any way to clean this up?</p>
