The example from the first mail has to be incomplete, because the "version"
function is never declared. This makes the question kind of moot and I can
only speculate.

In the following example the variable "o" will keep the prototype alive
because it is still reachable. If the allocation of "o" (i.e. the fourth
line) is removed, then the GC reclaims the memory just fine when calling
the exposed "gc" function and it goes from 43MB down to 0.5MB again after
the GC. Hope this speculation helps anyways.

function version() {}

// This will cause version.prototype to be reachable via o.__proto__!
var o = new version();

for(var i = 0; i < 100000; i++) {
  var buffer = [];
  buffer.length = 100000;
  version.prototype[i] = buffer;
}
version = undefined;
print("forcing GC!");
gc();

Best regards,
Michael


On Thu, Jun 27, 2013 at 6:46 PM, Lew Janyu <[email protected]> wrote:

> "version = undefined" seems not touch GC,
> but when I use "version.prototype = undefined", then the GC will
> collection immediately.
> I want to know why?
>
>
> On Thursday, June 27, 2013 10:41:08 PM UTC+8, Ben Noordhuis wrote:
>
>> On Thu, Jun 27, 2013 at 3:52 PM, Lew Janyu <[email protected]> wrote:
>> > Please view the code below:
>> >
>> > // d8 --expose-gc
>> >
>> > for(var i = 0; i < 1000000; i++)
>> > {
>> > // allocation huge memory
>> > var buffer = [];
>> > buffer.length = 100000;
>> > // assign to some native function's prototype
>> > version.prototype[i] = buffer;
>> > }
>> > // clean the function to dereference the buffers
>> > version = undefined;
>> > // force gc
>> > gc();
>> >
>> > print("gc was done, but the memory footprint is still huge. why?");
>> > // pause
>> > for(;;);
>>
>> Calling gc() doesn't guarantee that V8 will collect all garbage.  It
>> generally performs just enough collection to get by (something of a
>> simplification but approximately correct.)
>>
>> By the way, you mention 'memory footprint' but not if that means RSS or
>> VSZ.
>>
>  --
> --
> v8-users mailing list
> [email protected]
> 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 [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
-- 
v8-users mailing list
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to