Results 1 to 2 of 2
  1. #1
    nathey is offline Member
    Join Date
    Jul 2011
    Posts
    1
    Rep Power
    0

    Default Memory Allocation

    Just a quick and (hopefully) easy question about the actual memory allocation of lines of code.

    in the code:

    class Asdf{
    Object[] a;

    public Asdf(){
    a = new Object[0];
    }

    }

    is memory allocated for the array at the line Object[] a; or rather at the initialization inside the constructor?

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default

    Both.

    What you have to remember is that a is not an array. It is a variable that can reference an array. So the first line allocates memory for the variable. The other line allocates memory for the array object.

Similar Threads

  1. Arrays memory allocation
    By maya700 in forum New To Java
    Replies: 5
    Last Post: 07-16-2011, 09:47 AM
  2. JNI Memory Allocation
    By Smokin' Caterpillar in forum Advanced Java
    Replies: 3
    Last Post: 09-16-2010, 06:00 PM
  3. Memory Allocation
    By zzpprk in forum Advanced Java
    Replies: 2
    Last Post: 03-16-2010, 02:14 AM
  4. Array memory allocation
    By number5isalive in forum Advanced Java
    Replies: 8
    Last Post: 10-14-2009, 09:04 AM
  5. Memory Allocation
    By kishan in forum New To Java
    Replies: 3
    Last Post: 09-19-2009, 06:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •