Only unreachable objects will be garbage-collected. As long as you still have a (direct or indirect) reference to them, rest assured that they will stay around.
On Wed, May 21, 2014 at 2:13 PM, Si Robertson <retromodu...@gmail.com>wrote: > I think I understand. The concern I have is nothing within the closure > would be attached to anything outside of the closure, except for a few > persistent event listeners, so I'm unsure if V8 would flag everything as > volatile and/or garbage collect a load of objects because they are only > referenced by other objects within the closure. Would V8 not see the entire > closure as being eligible for garbage collection? > > > On Wednesday, 21 May 2014 10:29:45 UTC+1, Andreas Rossberg wrote: > >> On 21 May 2014 06:43, Si Robertson <retrom...@gmail.com> wrote: >> > Let's say someone has quite a large amount of code, possibly for a game >> or >> > application, and they wrapped all of that code in a closure ... >> > >> > (function(){ >> > // all code goes here >> > })() >> > >> > Would that cause any problems with V8 as far as optimisation and/or >> garbage >> > collection is concerned? >> >> If it is the closure environment you are worrying about, then this >> will be empty (assuming this expression occurs on the toplevel). A >> closure only closes over lexical or local variables, and (before ES6) >> the toplevel has neither. >> >> Generated code might actually be better, because all outermost >> variables of 'code' become local instead of polluting the global >> object, which should be more efficient in both time and space. >> >> /Andreas >> > -- > -- > v8-users mailing list > v8-users@googlegroups.com > http://groups.google.com/group/v8-users > --- > You received this message because you are subscribed to the Google Groups > "v8-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to v8-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.