Stack And Heap

Difference between Heap and Stack

Reference:

  1. stack memory is used to store local variable and function call.(primitive type value also store in stack)

  2. heap memory is used to store objects.

image

3.If there is no memory left in the stack for storing function call or local variable. JVM throw java.lang.StackOverFlowError

4.If there is no memory left in the heap for creating an Object,JVM throw java.lang.OutOfMemoryError

5.size of stack memory is a lot lesser than the size of heap.

6.Variables stored in stack are only visible to the owner Thread,While objects created in the heap are visible to all Thread. in other words,stack memory is kind of private memory of Java Threads while heap memory is shared among all threads.

###2.3Primitive Types and Values The primitive data types are:numberic types,and boolean type.

The numberic types consist of the integral types and the floating-point types.

The intergral types are:

  • byte,8-bit,from -128 to 127,inclusive
  • short,16-bit,from -32768 to 32767,inclusive
  • int ,32-bit,from -2的31次方到2的31次方-1
  • long,64-bit,
  • char,16bit.from 0 to 65535

The Ploating-point types are

  • float,32-bit
  • double,64-bit

What is the heap

The heap is the location where objects/class-instance are stored.It is much larger than the stack is and its value last longer than those in the stack. Anything created with the new operator will end up on the heap,and will be pointed to by one or more stack references or references in other heap objects.This memory is managed by GC.

转载于:https://my.oschina.net/tanghaoo/blog/686973

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值