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

  • SEARCH
  • Home
  • 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 7556623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:54:21+00:00 2026-05-30T11:54:21+00:00

I am working with a Javascript library (openlayers) and am trying to optimize some

  • 0

I am working with a Javascript library (openlayers) and am trying to optimize some of the classes to reduce the overall memory footprint. I’ve noticed that for some of the classes I have no need for a large portion of the methods of that class – they will never be called.

I was about to rewrite some of these classes, stripping out the methods I don’t need, but before I do I’d like to figure out whether or not that will have any noticeable effect on the memory footprint if I was to instantiate say 10,000 objects from the stripped-down class. Obviously if I remove properties that will help but I’m not sure about methods.

Can anyone give an explanation of how methods are stored, how much memory they consume, and possibly recommend any good books or other resources where I can bone up on this type of knowledge?

EDIT: Thank you for clarifying the difference between defining the method within the constructor function vs. the prototype. It appears to be a mixed bag but for the sake of argument let’s assume they’re defined in the constructor function (where it appears they’ll have the most impact).

  • 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-05-30T11:54:22+00:00Added an answer on May 30, 2026 at 11:54 am

    I think it really depends on whether a copy of your methods is created in memory for every instance of the object. For example:

    var MyObj = function(x) {
        this.doStuff = function() {
            //Do some stuff
        };
        this.someProperty = x;
    };
    //myInstance will have its own copy of the doStuff method
    var myInstance = new MyObj(10);
    

    In the above code, every instance of MyObj will require a copy of doStuff in memory. However, if the method was declared on the prototype, it’s a different story:

    var MyObj = function(x) {
        this.someProperty = x;
    };
    MyObj.prototype.doStuff = function() {
        //Do some stuff
    };
    //myInstance can still access doStuff, but all instances share one copy
    var myInstance = new MyObj(10);
    

    This time, every instance of MyObj has its own property someProperty, but when you call the doStuff method, its not found on the instance itself, so the prototype is looked at instead, where it is found and executed.

    However, if, as you say, there are methods that are not being called at all, I don’t see any reason to keep them no matter where they are declared. Personally, I would get rid of them (unless they are likely to provide value in the future). But I don’t know your code, so that’s a decision you will have to make.

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

Sidebar

Related Questions

I have some working Javascript code that generates an RDF/XML document using variables picked
I'm trying to reuse some script that I have working on another page, but
I am working on a Javascript object that contains some YUI objects. The key
I'm working with an existing javascript library that does an AJAX call and then
I've been working on a javascript library, and I have a lot of redundant
I have been working on a site that makes some pretty big use of
I am working in a Javascript library that brings in jQuery for one thing:
I am working with Magento which uses the prototype javascript library. Unfortunately some of
I'm working on a little library that lets me do some basic key value
I am working with the wonderful Knockout.js library. I am using javascript classes to

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.