zoukankan      html  css  js  c++  java
  • Oh My, JAVA?!

    Originally posted by Ilja Preuss:
    The "new" operator creates a new object of the ClassA type on the heap and returns a reference to the object. The reference is then assigned to the obj variable. As obj is a local variable, it lives on the stack.

    Does that help?



    To add, the starting point to make the distinction is the lifetime-predictability of the variable (reference).

    Since, for objects, the lifetime is unpredictable, they are always in the heap.

    For in-method variables (primitives and references), like Ilja explains, the lifetime is predictable, and hence in the stack.

    For instance variables (primitives and references), the lifetime is unpredictable, hence the heap.

    This holds for both references and primitives.

    I hope this properly summarizes the concept.                             

    http://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html

    JVM performance optimization, Part 3: Garbage collection

    http://www.javaworld.com/article/2078645/java-se/jvm-performance-optimization-part-3-garbage-collection.html

    How Garbage Collection Really Works

    http://www.dynatrace.com/en/javabook/how-garbage-collection-works.html

    JVM memory and garbage collection policy analysis model

    http://www.codeweblog.com/jvm-memory-and-garbage-collection-policy-analysis-model/

    Java (JVM) Memory Model and Garbage Collection Monitoring Tuning

    http://www.journaldev.com/2856/java-jvm-memory-model-and-garbage-collection-monitoring-tuning

    JVM performance optimization, Part 3: Garbage collection

    http://www.javaworld.com/article/2078645/java-se/jvm-performance-optimization-part-3-garbage-collection.html

    Java™ Memory: Understanding and Analyzing the Java Heap
    http://www-01.ibm.com/support/docview.wss?uid=swg27019232&aid=1
     

    Reference Types In Java - Part 1

    http://java.dzone.com/articles/reference-types-java-part-1

     
  • 相关阅读:
    【HDOJ1534】【差分约束+SPFA】
    【HDOJ3861】【Tarjan缩点+最小路径覆盖】
    【二分图最大权完美匹配】【KM算法】【转】
    学习一点汇编 INT 16H指令
    POJ2449 Remmarguts' Date 第K短路
    POJ3090 巧用欧拉函数 phi(x)
    POJ3420 递推+矩阵快速幂
    UVALive 4671 K-neighbor substrings 巧用FFT
    Tyvj 1068 巧用扩展KMP
    第四周 Leetcode 124. Binary Tree Maximum Path Sum (HARD)
  • 原文地址:https://www.cnblogs.com/lake-of-embedded-system/p/4372232.html
Copyright © 2011-2022 走看看