Free string-indexed Array memory

Discussion in 'Javascript' started by plumpickerpurplepaws@hotmail.com, Feb 9, 2007.

  1. Guest

    In this example:

    var x = [];
    x[0] = "Hello World!";
    x[1] = "Hello Alien!";
    x["world"] = 1;
    x["human"] = 0;
    x["alien"] = 0;

    how would I free only the memory allocated at line 5 (i.e. x["human"])?
     
    , Feb 9, 2007
    #1
    1. Advertising

  2. RobG Guest

    On Feb 9, 4:38 pm, wrote:
    > In this example:


    Incidentally, *all* array indexes are strings. If you specify a
    number, it is converted to a string.

    >
    > var x = [];
    > x[0] = "Hello World!";
    > x[1] = "Hello Alien!";
    > x["world"] = 1;
    > x["human"] = 0;
    > x["alien"] = 0;
    >
    > how would I free only the memory allocated at line 5 (i.e. x["human"])?


    delete x.human;


    --
    Rob
     
    RobG, Feb 9, 2007
    #2
    1. Advertising

  3. VK Guest

    var x = [];
    x[0] = "Hello World!";
    x[1] = "Hello Alien!";
    x["world"] = 1;
    x["human"] = 0;
    x["alien"] = 0;

    alert(x.length); // 2

    Only x[0] and x[1] will become array elements. "world", "human",
    "alien" are being added as custom property of x object but do not
    become array elements.

    Possibly it is what you wanted to, but worth to mention.


    delete operator can be used in either case
     
    VK, Feb 9, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. milkyway
    Replies:
    2
    Views:
    636
    Ryan Stewart
    Dec 26, 2004
  2. Replies:
    3
    Views:
    745
  3. Replies:
    2
    Views:
    333
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=
    Nov 15, 2006
  4. Panduranga Chary

    How memory function free() knows how much memory to free.

    Panduranga Chary, Dec 27, 2007, in forum: C Programming
    Replies:
    2
    Views:
    429
    Keith Thompson
    Dec 27, 2007
  5. Serge

    String-indexed array in ASP VBScript

    Serge, Dec 19, 2003, in forum: ASP General
    Replies:
    1
    Views:
    116
    Michael G. Schneider
    Dec 19, 2003
Loading...

Share This Page