Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8926635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:01:09+00:00 2026-06-15T08:01:09+00:00

https://github.com/joyent/node/blob/master/lib/freelist.js Making a destroy method is very dangerous. I suggest that if you’re concerned

  • 0

https://github.com/joyent/node/blob/master/lib/freelist.js

Making a destroy method is very dangerous. I suggest that if you’re
concerned about this then you use require(‘freelist’) and try to
reclaim memory after using it – which is what I do in net.js

It is for example used in https://github.com/joyent/node/blob/master/lib/http.js, but I still do not completely get it. An example of how this module could be used would be sweet.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:01:10+00:00Added an answer on June 15, 2026 at 8:01 am

    It’s very simple way to manage reuse of often created and destroyed objects. The freelist only creates new objects when no currently unused objects are available, reducing memory footprint without having to wait for garbage collection, etc. Using it involves three simple steps:

    Creating a new freelist for vectors (imaginary object type you want to reuse):

    // Some type of object I want to be able to reuse
    var Vector = require('./Vector');
    // The freelist itself
    var FreeList = require('freelist').FreeList;
    
    // Arguments are (freelistName, maxSize, constructorForNewObjects)
    var vectorsList = new FreeList('vectors', 1000, function() {
      // quick way to use constructor with arguments object
      return Vector.apply(Object.create(Vector.prototype), arguments);
    });
    

    Getting a new vector from the freelist:

    var vector = vectorsList.alloc(/* optional arguments for the Vector constructor /*);
    

    Freeing a vector that’s no longer needed:

    vectorsList.free(vector);
    

    That’s it.

    One very important thing to note:
    Although I have written above to pass the arguments from alloc calls on to the vector constructor, this only happens if there’s no free vector available in the list. Otherwise you just get the first available vector, still constructed with whatever parameters it had at construction time.

    If you want to actually initialize every object cleanly, you should probably not put the initialization of the object into the constructor, but into an init function that you always call after getting an object from the freelist.

    Ofcourse this could probably be done by the freelist with some clever hacking with calling the constructor again for initialization.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am viewing v8 header file, and got a problem again. https://github.com/joyent/node/blob/master/deps/v8/include/v8.h#L1408-1414 typedef Handle<Value>
https://github.com/jehrhardt/bigpipe-node/blob/master/app.js http://www.subbu.org/blog/2010/07/bigpipe-done-in-node-js I've noticed that all implementations of bigpipe need to flush the HTML.
in the rails source : https://github.com/rails/rails/blob/master/activesupport/lib/active_support/lazy_load_hooks.rb the following can be seen @load_hooks = Hash.new
https://github.com/seattlerb/zentest/blob/master/lib/autotest/autoupdate.rb It's not documented and I can't find any discussion about it on the
I'm basically following https://github.com/mattconnolly/devise-custom-strategy-demo/blob/master/lib/my_authentication.rb Everything works well, but there is one bug, if I'm
I'm following https://github.com/joyent/node/wiki/Using-Eclipse-as-Node-Applications-Debugger and leaves me with questions How can I see what variables
I am using Lightbox2 https://github.com/lokesh/lightbox2/blob/master/js/lightbox.js And I don't understand why all the inner members
Here is how I've done: https://github.com/joyent/node/wiki/Using-Eclipse-as-Node-Applications-Debugger but in the image after Now start making
https://github.com/nathanborror/django-basic-apps/blob/master/README.rst I am trying to implement this blog module my question is that the
https://github.com/LearnBoost/Socket.IO/tree/master/lib/vendor It can jump to another repository

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.