Results 1 to 6 of 6
  1. #1
    maya700 is offline Member
    Join Date
    Jun 2010
    Posts
    45
    Rep Power
    0

    Default Arrays memory allocation

    Hi all,

    I want to know where are the arrays basically stored?? Heap or stack???

    Thank you.

  2. #2
    fakepics500 is offline Member
    Join Date
    Jul 2011
    Posts
    43
    Rep Power
    0

    Default

    i think array are placed in heap because in stack
    The Java system must know, while it is creating the program, the exact lifetime of all the items that are stored on the stack

  3. #3
    maya700 is offline Member
    Join Date
    Jun 2010
    Posts
    45
    Rep Power
    0

    Default

    But what if i declare an array irrespective of its type inside the method. Isn't that supposed to go on stack according to java memory doctrines???

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Where do you think it gets stored and why?

  5. #5
    maya700 is offline Member
    Join Date
    Jun 2010
    Posts
    45
    Rep Power
    0

    Default

    May be i guess it all depends on the its definition than on its type. I mean irrespective of primary or reference type it all goes where the user is defining it, inside the method or outside of it. Correct me if am wrong. I need some clear view on this one.

    Thank you.

  6. #6
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You can think of an array as an object which holds x items
    Java Code:
    public class MyArray{
      public int length = 3;
      int value1;
      int value2;
      int value3;
    }
    Is somewhat similar to
    Java Code:
    int[] x = new int[3];
    I must admit this example was found on another post, available here: Java Array is stored in stack or heap? - Stack Overflow

    Arrays are stored on the heap.

Similar Threads

  1. Arrays memory addresses
    By Dayanand in forum New To Java
    Replies: 2
    Last Post: 03-04-2011, 10:17 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
  •