AFAIK, it will be garbage collected.
The reference to the first object is 'deleted' ('a' now points to a
different object), and as nobody holds a reference to the first object, it
will be collected.

--
S.Cinos
JavaScript Developer at Tuenti.com



2010/12/7 Adrian Olaru <[email protected]>

> Hi guys,
>
> I have this code:
>
> var a;
>
> function init() {
>   a = new SomeObject("one");
>   a.doSomething();
>
>   a = new SomeObject("two");
>   a.doSomething();
> }
>
> init();
> a = null;
>
> What happens with the first object created and assigned to a? It's this an
> example of memory leaking, or will be garbage collected?
>
> Now, I know about garbage collection and how is implemented in browser
> (mark-and-sweep vs ref count (ie) ), but still, I wanna be sure.
>
> Thanks.
>
> _______________________________________________
> JSMentors mailing list
> [email protected]
> http://jsmentors.com/mailman/listinfo/jsmentors_jsmentors.com
>
>
_______________________________________________
JSMentors mailing list
[email protected]
http://jsmentors.com/mailman/listinfo/jsmentors_jsmentors.com

Reply via email to