Java Static vs Stack with Thread

As far as I know all the static variables and static methods will go on Static and all the methods, local variables and reference variable that declare in the method will go on Stack, but what about local variables and reference variables in a static method ? I guess they will be allocated on the Stack, but I am not sure how does it work. For example: public static void A(){ int x = 3;

Java静态与堆栈与线程

据我所知,所有的静态变量和静态方法将继续静态和所有的方法,在方法中声明的局部变量和引用变量将继续Stack,但是静态方法中的局部变量和引用变量呢? 我想他们会被分配到堆栈中,但我不确定它是如何工作的。 例如: public static void A(){ int x = 3; Point p = new Point(); } 另外我想所有的线程共享静态以及他们共享堆,正确的? 您可以将局部变量视为始终在执行线程的堆栈上分配。 我猜JIT编译器

Does a static variable go on the permanent gen space on the heap

If I create a static variable in Java, does it automatically go into the perm gen space on the heap? it seems obvious that the answer is yes, but i cannot find the confirmation anywhere. I know the static variable (also strings and enums) are alive for the life of the JVM so it must go on the permanent heap. IS this correct? The idea of the "PermGen" is completely implementation-de

一个静态变量是否在堆上的永久gen空间上

如果我在Java中创建一个静态变量,它会自动进入堆中的perm gen空间吗? 似乎很明显,答案是肯定的,但我无法在任何地方找到确认。 我知道静态变量(也是字符串和枚举)在JVM的生命中是活着的,所以它必须放在永久堆中。 它是否正确? “PermGen”的概念完全依赖于实现,JVM可以自由处理“物理”内存管理,但对他们来说是有意义的 - 他们甚至不需要提供垃圾收集! PermGen只是某些JVM实现(包括Sun / Oracle HotSpot JVM多年)

Maximizing Java Heap Space

I'm trying to use very large square matrices in Java, on the order of n = 1e6 or more. The matrices aren't sparse, so I don't see much way around representing them as a 2D array, which requires n^2 * sizeof(int) bits of memory. Obviously, I'm getting heap overflow errors, even when adding compiler flags to use as large a heap as my machine will allow. I'm willing to assume

最大化Java堆空间

我试图在Java中使用非常大的矩形矩阵,大小为n = 1e6或更多。 矩阵并不稀疏,所以我没有看到将它们表示为二维数组,它需要n ^ 2 * sizeof(int)位内存。 显然,即使在我的机器允许的情况下添加编译器标志以像堆一样使用时,我也会遇到堆溢出错误。 为了这个问题,我愿意假设我有完美的计算机(无限RAM等),尽管实际上我是在一台拥有16个RAM的64位机器上。 看起来我的机器是如此相关,因为我受JVM的限制,而不是我的实际硬

Is it possible to destroy static variables programmatically?

I want to destroy static object programmatically. Is it possible? If yes then how can i achieve this. Kindly suggest. The thing that you need to understand is - the references are static, the objects aren't. By that, I mean to say, in static SomeClass someClassInstance = new SomeClassInstance(); the static property is on the reference someClassInstance and GC acts on instances / obj

是否有可能以编程方式销毁静态变量?

我想以编程方式销毁静态对象。 可能吗? 如果是的话,我该如何做到这一点。 请建议。 你需要明白的是 - 引用是静态的,对象不是。 由此,我的意思是说,在 static SomeClass someClassInstance = new SomeClassInstance(); 静态属性位于引用someClassInstance ,GC作用于实例/对象。 someClassInstance =null将使第一个SomeClassInstance符合GC的条件。 根据定义,每个类定义一个静态变量,并且(如果声明为final

Where java static variables are stored in memory?

class A{ static int i = 10; static int j = 20; static void getname(){ } } 这些变量在哪里存储在内存中? simply said , Static Variables are stored in HEAP . Classes and all of the data applying to classes (not instance data) is stored in the Permanent Generation section of the heap. If you need elaborated answer , refer this static allocation in java - heap, stack and permanent genera

哪里java静态变量存储在内存中?

class A{ static int i = 10; static int j = 20; static void getname(){ } } 这些变量在哪里存储在内存中? 简单地说, 静态变量存储在HEAP中 。 类和适用于类的所有数据(不是实例数据)存储在堆的永久生成部分。 如果你需要详细的答案,请参考这个 在Java中的静态分配 - 堆,堆栈和永久生成 首先,静态成员变量存储在堆的永久生成区域中。 你的例子包含原始类型变量,它们将被存储在PermGen中。 如果这

What is the actual memory place for static variables?

Static variable is allocated for the entire duration of program's execution, so neither stack nor heap are convenient for it. Then where is it? There should be some place where it is loaded ? Static fields are initialised when a class is loaded and and are discarded when the classloader for that class is unloaded. They can be cleaned up, even duplicated in another class loader. For app

什么是静态变量的实际内存空间?

静态变量分配给整个程序执行期间,所以堆栈和堆都不方便。 那它在哪里? 应该有一些地方加载? 当一个类被加载时静态字段被初始化,并且当该类的类加载器被卸载时被放弃。 它们可以被清理,甚至可以在另一个类加载器中复制。 对于那些使用OSGi的应用程序来说,静态变量在应用程序的整个生命周期内都不会生效,可以重新加载多次。 这是如何实现的可能依赖于JVM,但Sun / Oracle JVM创建一个“对象”来保存类的静态字段。

Where are static methods and static variables stored in Java?

For example: class A { static int i=0; static int j; static void method() { // static k=0; can't use static for local variables only final is permitted // static int L; } } Where will these variables be stored in Java, in heap or in stack memory? How are they stored? Static methods (in fact all methods) as well as static variables are stored in the PermGen secti

在Java中存储静态方法和静态变量在哪里?

例如: class A { static int i=0; static int j; static void method() { // static k=0; can't use static for local variables only final is permitted // static int L; } } 这些变量将在Java中,堆或栈内存中存储在哪里? 他们如何存储? 静态方法(实际上所有的方法)以及静态变量都存储在堆的PermGen部分,因为它们是反射数据的一部分(与类相关的数据,与实例无关)。 澄清更新:

Memory allocation during class loading

Possible Duplicate: static allocation in java - heap, stack and permanent generation Looking to understand what EXACTLY happens (in terms of memory management) when a class is loaded by JVM. Specifically: Which part of memory is the actual class byte code loaded/placed? Which part of memory are the static variables loaded/placed? Which part of memory are the other variables and methods

在类加载期间的内存分配

可能重复: 在Java中的静态分配 - 堆,堆栈和永久生成 希望了解当JVM加载类时,究竟发生了什么(就内存管理而言)。 特别: 哪部分内存是实际的类字节代码加载/放置? 哪部分内存是加载/放置的静态变量? 哪部分内存是其他变量和方法的加载/放置? 首先将包含该类的字节数组加载到PermGen中。 然后解析类字节数组,并将一些解析的信息放入PermGen中。 然后,班级中的字符串被内化(并放入PermGen中)。 当类

where the memory allocated when we declare static?

Possible Duplicate: static allocation in java - heap, stack and permanent generation its a small confusion...defining static to class, methods and variables.In this three cases where thus the memory allocated. ? My boss is familiar with C,he says only variables are in heap memory and rest (static classes and static methods) will remain in main memory. is that ture? any explanation.? one

我们声明静态时分配的内存在哪里?

可能重复: 在Java中的静态分配 - 堆,堆栈和永久生成 它的一个小混乱...定义静态类,方法和变量。在这三种情况下,因此内存分配。 ? 我的老板熟悉C语言,他说只有变量存在于堆内存中,而其余的(静态类和静态方法)将保留在主内存中。 那是真的吗? 任何解释。? 在使用静态类和静态方法的android中还有一个是最佳实践? 尝试这个, static members are stored in Method Area. 类实例和数组存储在堆内存中。

Where are Metaspace and Runtime Constant pools in JVM's memory?

I'm confused with Metaspace in Java. Where is it? Some articles treating PermGen(Metaspace) as part of the heap, some of them as heap-off part of memory: Method Area (part of Metaspace) is the part of heap here: http://javapapers.com/core-java/java-jvm-run-time-data-areas/ and here's not: http://blog.jamesdbloom.com/JVMInternals.html I've got the same problem with runtime cons

JVM内存中的Metaspace和Runtime常量池在哪里?

我在Java中与Metaspace混淆。 它在哪里? 一些将PermGen(Metaspace)作为堆的一部分的文章,其中一些作为堆的部分内存: 方法区(Metaspace的一部分)是堆的一部分:http://javapapers.com/core-java/java-jvm-run-time-data-areas/ 这里不是:http://blog.jamesdbloom.com/JVMInternals.html 我遇到了与运行时常量池相同的问题。 一些文章将其视为堆的一部分,其中一些文章像方法区的一部分。 它取决于JVM的实现,