1 Reply Latest reply: Jul 6, 2011 2:07 PM by 796440 RSS

    Memory Storage location ?

    866541
      say we have below method

      Public void test1(int i, AccountInfo accInfo)
      {
      CustomerInfo custInfo = new CustomerInfo();
      }

      In above case CustomerInfo object will be created on heap but its reference i.e custInfo will be stored in stack. Correct?

      Same is true for object parameters (like accInfo) but prmitive type method will be stored in stack right?
        • 1. Re: Memory Storage location ?
          796440
          JavaFunda wrote:
          say we have below method

          Public void test1(int i, AccountInfo accInfo)
          {
          CustomerInfo custInfo = new CustomerInfo();
          }

          In above case CustomerInfo object will be created on heap but its reference i.e custInfo will be stored in stack. Correct?
          Correct.

          Except that when you say "its reference," it sounds like it has one single reference which is inherently tied to it. That is not the case. This particular reference (the one stored in the custInfo varible) will be on the stack.
          Same is true for object parameters (like accInfo) but prmitive type method will be stored in stack right?
          All method parameters and all local variables are on the stack. If the method parameter or local variable is a reference type, then the object it points to will be on the heap.

          Note that there is no such thing as an "object parameter," in that no parameter (or local variable) ever has an object as its value--only a reference.