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 4058324
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:03:55+00:00 2026-05-20T15:03:55+00:00

Out of interest, is it possible to determine the size of a JavaScript variable,

  • 0

Out of interest, is it possible to determine the size of a JavaScript variable, in bytes?

I have a web-app that runs great on the desktop but blows up* on the iPad. I’m guessing it’s because there’s a much more limited amount of memory in iPad Safari, but I’d like to get some idea of what’s going on in my app.

I can estimate relative sizes, based on the size of the JSON source, but it’ll be even better to know the actual size of the serialised object

  • “Blows up” = Safari slows down, then the screen goes black, and I’m back to the standard iPad home screen. Whatever that’s called. Looks to me, that Safari has run out of the memory allocated for a browser instance.
  • 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-20T15:03:56+00:00Added an answer on May 20, 2026 at 3:03 pm

    This won’t directly answer your question. The JS language reference doesn’t specify how to store data, so it’s up to the groups doing the implementation, in this case the WebKit team, and I’ve not seen anything public on that. I’ve definitely not seen anything about Mobile Safari’s implementation of WebKit.

    What I would say is that things may actually not be running great on the desktop, it’s just that the the desktop’s speed and size masks “problems” that show up on the mobile devices. On iOS, a browser instance has a ceiling of 10MB in which to operate if I remember correctly, though in practice, you start to hit the wall right around 6 or 7MB. On a PC, when you run out of RAM, the computer will simply just dump out unused memory to the disk. On iOS either resources stop loading (such as images) or the browser just exits (which is probably what you are experiencing).

    If you have a Mac, you can snoop on Safari to see how it’s doing by using a tool called “Instruments” (it’s part of the iOS SDK). If you don’t have a Mac or don’t want to download the SDK, just open a clean instance of Safari, open up Windows’ Task Manager or Mac’s Activity Monitor and watch how your memory usage changes when you load up your webapp.

    Staying within the 6MB window is annoying. The biggest thing is try to avoid creating new images. For example, this pattern is a huge problem on an iPhone:

    function placeImage(imagename,targetelement) { 
        var image = new Image();
        image.src = imagename;
        targetelement.appendChild(image);
    }
    

    In this case, even if you remove the image from the DOM, and even though image is scoped within placeImage, it will never, ever get released and it is just a matter of time before this application crashes the browser. If this is your case, instead think about how many images you need to display at once, create image objects only for those elements and recycle them (just reset the src any time you want a new image).

    Also, I’ve found that JavaScript’s application stack is much smaller than on a desktop browser, so if you have a lot of recursion, you’ll see the problem much faster on iOS. The way to spot this problem is to open up the Developer Tools in Safari and use the profiler to see what functions are getting called the most.

    [edit] I can’t remember if this is the exact technique that exposes how numbers are stored differently internally by webkit, but I think it is. Basically, you do a sort on a million random numbers, first with a float, then (if you uncomment the line) an integer and then a large integer. I’m not good with typed languages, so I’m not exactly sure what this proves other than that internally numbers are treated differently depending on their smallest possibly representation.

    arrTarget = [];
    for (var i = 0; i < 1000000; i++) {
        arrTarget.push(Math.random() * 16000000);
    //  arrTarget.push(Math.floor(Math.random() * 16000000));
    //  arrTarget.push(Math.floor(Math.random() * 1600000000000));
    }
    
    // Time how long it takes to sort the array:
    var time = new Date().getTime();
    arrTarget.sort();
    console.log(new Date().getTime() - time);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My desktop app connects to a web application that's hosted on Google App engine.
More out of interest than anything else, but can you compile a DirectX app
I am writing an app in javascript to try to figure out item builds
Just out of interest , is it possible to call a C module from
Out of interest and because it infuriates me, I was wondering if SOmebody here
This question is just out of interest, and perhaps could be useful for my
I'm trying to answer the following question out of personal interest: What is the
Out of the box SSRS reports cannot have data exposed in the page header.
Out of order execution in CPUs means that a CPU can reorder instructions to
I would like to write an application, for my own interest, that graphically visualizes

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.