Jay Kyburz
Jay Kyburz

Reputation: 699

Memory Footprint of Javascript Code

I have a largish web app that uses a Javascript inheritance style that duplicates the methods of every object for every instance.

Can anybody tell me how I can estimate how much memory is being consumed to store a duplicate of each function for each instance?

I've seen posts that help estimate the variable usage, but what about the instructions, the code itself?

For example:

function createAnimal() {
    var self = {};
    self.think = function () {
        consol.log("thinking");
    };
    return self;
}

function createDog () {
    var self = createAnimal();
    self.bark = function () {
        console.log("woof woof");
    };
    return self;
}


var spot = createDog();
var ralph = createDog();

Upvotes: 0

Views: 426

Answers (1)

stark
stark

Reputation: 13189

In firefox go to about:memory. Under js it lists the memory usage:

├──19.78 MB (34.58%) -- js
│  ├───9.87 MB (17.25%) -- compartment([System Principal], 0x336e000)
│  │   ├──4.72 MB (08.25%) -- gc-heap
│  │   │  ├──2.33 MB (04.07%) -- objects
│  │   │  ├──1.48 MB (02.58%) -- shapes
│  │   │  ├──0.59 MB (01.03%) -- scripts
│  │   │  └──0.33 MB (00.57%) -- (6 omitted)
│  │   ├──1.18 MB (02.06%) -- script-data
│  │   ├──1.00 MB (01.75%) -- mjit-code
│  │   │  ├──0.92 MB (01.60%) -- method
│  │   │  └──0.08 MB (00.15%) -- (2 omitted)
│  │   ├──0.68 MB (01.19%) -- analysis-temporary
│  │   ├──0.60 MB (01.04%) -- (5 omitted)
│  │   ├──0.48 MB (00.84%) -- object-slots
│  │   ├──0.46 MB (00.81%) -- mjit-data
│  │   ├──0.41 MB (00.72%) -- property-tables
│  │   └──0.34 MB (00.59%) -- string-chars

Upvotes: 2

Related Questions