哪位高人能给讲下堆内存和栈内存,哪些是放在堆内存,哪些是在栈内存?谢谢!!
解决方案 »
- java正则问题,怎么去掉全是空格的行?
- 关于return的问题,帮我看看代码这样写有没有问题,谢谢
- Java 线程问题,这种线程创建的方法,算什么意思?
- 我想调用get方法,然后根据这个类里面的一个falg的类型,来决定返回什么数据类型
- 请问如何 用java 读cpu 的 id ?
- 我在编写一个记事本的java程序,但是无法解决对选定字符内容的字体更改,希望哪位大虾可以帮助解决?
- 我的swing程序在jbuilder运行,图片按钮可以正常出现,但编译之后成exe图片按钮没出现,请教
- java and jsp有什麽区别呀??
- TOMCAT怎么设置啊~?
- 请问大家JAVA有什么好书,对于初学者来说????
- 一个窗口的事件监听函数里如何更新另外一个窗口类的变量
- 如何实现这样的功能
a = new int [10];
首先在栈中分配一块内存放变量a,这时候a指向null, 然后用new 在堆栈中分配可以放10个整数的内存。并且把首地址送到变量a所在的栈内存空间里
这和C++不一样。你可以翻看以前很多贴字,都有这个话题的,不过最好是看我说的
动态分配内存,new,或static!
栈内存
一些局部变量,如 public void n{ int x = 0; //作用域完了,x就完了}
------------------------
栈内存,一般都是作用域完了自动调用析构函数的(在java没有这个概念,但还是可以理解为他带有)
堆内存,这是和GC机制有关的!
The Java VM manages two kinds of memory: heap and non-heap memory, both of which are created when the Java VM starts.Heap memory is the runtime data area from which the Java VM allocates memory for all class instances and arrays. The heap may be of a fixed or variable size. The garbage collector is an automatic memory management system that reclaims heap memory for objects.Non-heap memory includes a method area shared among all threads and memory required for the internal processing or optimization for the Java VM. It stores per-class structures such as a runtime constant pool, field and method data, and the code for methods and constructors. The method area is logically part of the heap but, depending on the implementation, a Java VM may not garbage collect or compact it. Like the heap memory, the method area may be of a fixed or variable size. The memory for the method area does not need to be contiguous.In addition to the method area, a Java VM may require memory for internal processing or optimization which also belongs to non-heap memory. For example, the Just-In-Time (JIT) compiler requires memory for storing the native machine code translated from the Java VM code for high performance