In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
What is the concept of memory allocation in Java? I believe many inexperienced people are at a loss about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Java program runs on JVM (JavaVirtualMachine,Java virtual machine), JVM can be understood as a bridge between Java program and operating system, and JVM realizes the platform independence of Java.
Register: JVM internal virtual register, access speed is very fast, the program is uncontrollable.
Stack: holds the value of local variables: including 1. The value of the basic data type. two。 Save an instance of the class, that is, a reference (pointer) to the heap area object. 3. Saves the frame at which the loading method is loaded.
Heap: used to store dynamically generated data, such as objects from new. Note that the created objects contain only member variables that belong to each other, not member methods. Because the same class has its own member variables, stored in different locations in the heap, but different instances of the same class share the method of the class, and do not copy the member method every time an object is created.
Constant pool: JVM maintains a constant pool for each loaded type, which is a collection of constants used by this type. Includes direct constants (primitive types, String) and symbolic references to other types, methods, and fields (1). The data in the pool is accessed through the index like an array. Because constant pools contain all symbolic references to other types, methods, and fields of one type, constant pools play a central role in dynamic linking of Java. The constant pool exists in the method area, while the method area exists in the heap.
This paper describes the memory allocation of Java, and then explains in detail how the Java program runs in memory through an example.
Preliminary knowledge:
1. A Java file, as long as there is a main entry method, we think that this is a Java program, which can be compiled and run separately.
two。 Whether it is a variable of a normal type or a variable of a reference type (commonly known as an instance), it can be used as a local variable, and they can appear on the stack. It's just that a variable of an ordinary type stores its corresponding value directly in the stack, while a variable of a reference type holds a pointer to the heap area, through which the object corresponding to this instance in the heap area can be found. Therefore, ordinary type variables occupy only one piece of memory in the stack area, while reference type variables occupy one piece of memory in the stack area and one piece of memory in the stack area.
3. In the parameter passing of the method, the basic data type, the String class, is passed by value, that is, a copy! The reference data type is passed by reference, that is, passing in the address in the stack!
After reading the above, have you mastered the concept of memory allocation in Java? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.