I'm not a JavaScript professional, so my question might seem ridiculous. Suppose i have the following HTML block:
<div>
<script type="text/javascript">
var variable_2 = new SomeObject();
</script>
</div>
This clearly allocates memory on the heap for the SomeObject instance and variable_2 resides in the global context.
My question is: If I have generated the previous HTML block again by using AJAX, i will then have variable_2 reference a newly allocated instance of SomeObject in the global context, right? But then, what happens to the previously allocated instance, is it garbage collected or this is a memory leak?
In addition, if you may include a reference to a book or article that describes the best practices of JavaScript memory management?