Skip to content

JavaScript does not provide a sizeof (like in C), and programmer does not need to care about memory allocation/deallocation. But how can we check how much memory an object occupies?

Notifications You must be signed in to change notification settings

alaeddinejebali/Check-how-much-memory-an-object-occupies-in-javascript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Check how much memory an object occupies in JavaScript

JavaScript does not provide a sizeof (like in C), and programmer does not need to care about memory allocation/deallocation. But how can we check how much memory an object occupies?

Primitive types

Let's say that you have a string:

var stringObject =  String("Ala Eddine JEBALI");

How to implement a memorySizeOf function which returns the memory size of stringObject?

memorySizeOf(stringObject)

Other objects

Let's say that you have this object:

var personObject =  {persone: {name: 'Ala Eddine JEBALI', country: 'France', age: 30}};

How to implement a memorySizeOf function which returns the memory size of personObject?

memorySizeOf(personObject)

Remark

The result is of course the same when you want to check

console.log( memorySizeOf(123) );

or

console.log( memorySizeOf(Number(123)) );

The output is:

8 bytes

About

JavaScript does not provide a sizeof (like in C), and programmer does not need to care about memory allocation/deallocation. But how can we check how much memory an object occupies?

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published