内存分配和变量的生命 [英] Memory allocation and life of variables

查看:88
本文介绍了内存分配和变量的生命的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题或更确切的问题如下:

My question or rather questions are as follows:

1)静态变量驻留在哪里。有些文章称它们位于堆上,有些人在perm gen区域中使用类定义,因为它们是类属性。我理解第二个选项可能是正确的,因为它是一个类属性。

2)最终变量驻留在哪里以及它的生命如果:
a)它是一个类型为primitive的实例变量b $ bb)它是一个类型为primitive的方法的局部变量
c)它是一个类型为
b的实例变量。它是类型引用方法的局部变量

3)如果它们是本地变量,那么存储的参考局部变量在哪里。

4)在数组的情况下,内存分配有任何差异,因为它们是实例变量或本地线程变量。

1)Where does the static variable reside . Some articles say they reside on the heap and some some say in the perm gen area with the class definition as they are class attributes. I understand the second option might be correct because it is a class attribute.
2)Where does the final variable reside and what is its life if: a) Its an instance variable of type primitive b) Its a local variable of a method of type primitive c) Its an instance variable of type reference b) Its a local variable of a method of type reference
3)Where are the reference local variables stored if they are local.
4)In case of arrays is there any difference in memory allocation as in they are instance variable or local thread variable.

谢谢

推荐答案

静态变量驻留

- 静态变量驻留在方法区域,permgen位于Method区域内。

- static variable resides in Method Area, and permgen is inside Method area.

Where does the final variable reside and what is its life if
Its an instance variable of type primitive

- 如果是它的实例变量,它保留在它所属的Object 中的堆,并且不在范围内,因为没有对包含它的Object的引用..

- If its instance variable, it stays on the Heap inside the Object to which it belongs, and falls out of scope as there is no reference to the Object which holds it..

它是原始类型方法的局部变量

- 它停留在堆栈上,并且在达到大括号的方法时超出了范围......

- It stays on the Stack, and and falls out of scope as there as the methods closing brace is reached...

类型为reference的实例变量

- 它保留在对象内的堆中,并且超出范围,因为没有对持有它的Object的引用..

- it stays on the Heap inside the Object to which it belongs, and falls out of scope as there is no reference to the Object which holds it..

类型参考方法的局部变量

- 它停留在堆栈上,并且不属于到达大括号的方法的范围...

- It stays on the Stack, and and falls out of scope as there as the methods closing brace is reached...

如果参考局部变量是本地变量,它们在哪里存储。

- 在筹码上......

- On the Stack...

如果数组的内存分配有任何差异,例如它们是实例 变量或本地线程变量。

- 以及数组是一个对象它存储在中。 ...但是从 Java 6u23 版本开始,已经引入了 Escape Analysis ,根据这个,如果 JVM决定Object不能转义Method,它会尝试在Thread上创建Object的斯塔克,NOT ON HEAP ....

- Well as Array is an object it is stored on Heap....but from Java 6u23 version, there has been the introduction of Escape Analysis, according to this if the JVM decides that the Object canNot escape the Method, it will try creating the Object on the Thread's Stack , NOT ON HEAP....

这篇关于内存分配和变量的生命的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆