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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:28:58+00:00 2026-05-30T20:28:58+00:00

I am thinking about memory allocation in Java i.e in which memory location methods,

  • 0

I am thinking about memory allocation in Java i.e in which
memory location methods, fields and objects are stored.

Suppose I have 2 classes

import java.util.*;
class ABC
{
int field;
List<Integer>l;
}   
class XYZ 
{
int x,y,z;
static int p;
void fun(ABC a){
    a.field = 10;
    a.l = new ArrayList<Integer>(10);
    a.l.add(10);
}
}   
public class Simulator{
public static void main(String[] arg){
    XYZ tmp_1 = new XYZ();
    ABC tmp_2 = new ABC();
    tmp_1.fun(tmp_2);
    System.out.println(tmp_2.l);
}

}

Now where will the memory be allocated for each of the data members,functions and objects be allocated ?

My thoughts are objects, data-members will be stored in Heap but I am not sure about functions and their data members ?

  • 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-30T20:28:59+00:00Added an answer on May 30, 2026 at 8:28 pm

    Here’s a breakdown of how the different things that you refer or allude to are stored:

    • Local variables and method / constructor parameters can contain either primitive values or references to objects or arrays. (They cannot contain the objects or arrays themselves.) Locals and parameters are stored in activation frames (to use the JLS terminology), and these frames are stored on a thread’s stack. Thread stacks are non-heap memory in typical JVMs.

    • Objects and arrays are represented in heap memory.

    • Instance fields (containing primitive or reference values) are stored in objects, and hence in the heap.

    • Array elements (either primitive or reference values) and the length of an array are stored in the array and hence in the heap.

    • Static fields are stored in special frames called static frames. These frames are stored in the heap.

    • The code of Java methods (in byte-code and native code form) is typically represented by code blocks that are stored in the heap.


    Note that the above is based on what happens in a typical JVM. In fact, the Java Language Specification does not mandate that things are stored in a stack or a heap. The terms stack memory and heap memory hardly appear in the JLS at all, and it is conceivable that other memory organization schemes could be used.

    Also, “the heap” is an over-simplification, because a HotSpot JVM / GC typically divides the heap into areas with different characteristics. For instance the “permgen” area of the heap (where static frames and code blocks are allocated) is only garbage collected rarely.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was thinking about some memory pool/allocation stuff I might write so I came
I'm thinking about a hash function for arbitrary Java-objects for exercise means. The naive
Lee Brimelow got me thinking about my Flash Application CPU and Memory consumption in
I have been reading about out of memory conditions on Linux, and the following
I have read several threads about memory issues in R and I can't seem
I have been thinking a little about environment variables and have a few questions/observations.
I have a few questions about PHP memory usage. I'm going to run some
I'm thinking about creating an application (or refactoring other in-house software) which could work
I am thinking about how much a class resides in memory in case it
I recently got thinking about alignment... It's something that we don't ordinarily have to

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.