`
hanhg
  • 浏览: 133293 次
  • 性别: Icon_minigender_1
  • 来自: 沈阳
社区版块
存档分类
最新评论

What’s memory leak?

阅读更多
 How does garbage collection work?
The job of the garbage collector is to find objects that are no longer needed by an application and to remove them when they can no longer be accessed or referenced. The garbage collector starts at the root nodes, classes that persist throughout the life of a Java application, and sweeps though all of the nodes that are referenced. As it traverses the nodes, it keeps track of which objects are actively being referenced. Any classes that are no longer being referenced are then eligible to be garbage collected. The memory resources used by these objects can be returned to the Java virtual machine (JVM) when the objects are deleted.
So it is true that Java code does not require the programmer to be responsible for memory management cleanup, and that it automatically garbage collects unused objects. However, the key point to remember is that an object is only counted as being unused when it is no longer referenced. Figure 1 illustrates this concept.

 For Example
The figure illustrates two classes that have different lifetimes during the execution of a Java application. Class A is instantiated first and exists for a long time or for the entire life of the program. At some point, class B is created, and class A adds a reference to this newly created class. Now let's suppose class B is some user interface widget that is displayed and eventually dismissed by the user. Even though class B is no longer needed, if the reference that class A has to class B is not cleared, class B will continue to exist and to take up memory space even after the next garbage collection cycle is executed.

 How the JVM uses system memory for its heap
When running java.exe, you can use certain options to control the startup and maximum size of the garbage-collected heap (-ms and -mx, respectively). The Sun JDK 1.1.8 uses a default 1 MB startup setting and a 16 MB maximum setting. The IBM JDK 1.1.8 uses a default maximum setting of one-half the total physical memory size of the machine. These memory settings have a direct impact on what the JVM does when it runs out of memory. The JVM may continue growing the heap rather than wait for a garbage collection cycle to complete.
分享到:
评论

相关推荐

    微软内部资料-SQL性能优化2

    Application memory tuning provides more of the computer's virtual memory to applications by providing less virtual memory to the operating system. Although a system having less than 2 GB of physical ...

    Android代码-android-arduino-nes-controller

    This is an Arduion based NES controller for ... There do seem to be some issues with my phone slowing down while I'm using it, not sure if that's because of debug code or memory leak or something else. I

    Oracle WebLogic Server 10gR3: Troubleshooting Methodologies

    Analyzing and Diagnosing Out of Memory/Memory Leak Patterns Review of General Memory Concepts: Java Heap, Native Memory, and Memory Leaks Investigating Java Heap Out of Memory Errors Review Garbage ...

    Debugging Malloc Lab: Detecting Memory-Related Errors

    Error #5: Memory leak detection (user can use ALLOCATEDSIZE to check for leaks at the end of the program) To report the first four errors, call one of these two functions: void error(int errorcode...

    Gobi3000代码 高通

    Fix memory leak in device detection Prior Release (Gobi3000 API 2011-07-29-1026) a. Internal changes to the COM layer to remove dependency on async IO libraries - requires GobiNet 1.0.60 or newer b...

    libevent-1.1b_1.4.13-stable_2.0.3-alpha 源码(资料中转)

    libevent-2.0.1-alpha.tar.gz [GPG Sig] - What's new - Release 2009-04-17 libevent-1.4.10-stable.tar.gz [GPG Sig] - ChangeLog - Release 2009-04-17 libevent-1.4.9-stable.tar.gz [GPG Sig] - ChangeLog - ...

    ActiveState Komodo IDE 10.2.1.89853 Setup + Keygen

    Additionally we've fixed a long standing memory leak which caused users to have to restart Komodo every few days, that should no longer be the case. - Other Mentionables - Improved source code ...

    Sakemail

    .- Reduced the line sleep to 30 (tell me if this value doesn‘t work for you).27/4/981.7.0- Fixed a memory leak, thanks to Don Higgins.- Moved the string esErrorInFormatOfMsg to a property of SakPOP.-...

    S7A驱动720版本

    - Passing of invalid OPC Item IDs caused a memory leak of the driver's global memory. After the global memory was exhausted, the driver crashed. - Writing of string values failed when using ...

    JavaScript Applications with Node.js, React, React Native and MongoDB

    14.3. Memory Leak Detection 14.4CI/CD 14.5Monitoring and Alerting PARTIII: The Presentation Laver (React/HTML) Chapter 15: Fundamentals 15.1Defnition of the Presentation Layer 15.2Introducing React ...

    php.ini-development

    application users can inadvertently leak otherwise secure information. ; This is php.ini-development INI file. ;;;;;;;;;;;;;;;;;;; ; Quick Reference ; ;;;;;;;;;;;;;;;;;;; ; The following are all ...

    STG (SNMP Traffic Grapher)

    One memory leak fixed. Features added: 1. Resizeable window. Changes in version 1.3.2: Bugs fixed: 1. Corrected bug with zero replies not included in Avg value. Thanks to Rafael Prado Rocchi! ...

    acpi控制笔记本风扇转速

    Fixed a possible memory leak and fault in AcpiExResolveObjectToValue during a read from a buffer or region field. (BZ 458) Fiodor Suietov. Example Code and Data Size: These are the sizes for the OS- ...

    VclZip pro v3.10.1

    PLEASE TAKE A LOOK AT THE "WHAT's NEW IN THIS VERSION" LINK IN THE HELP FILE AS IT HAS CONVENIENT LINKS TO ALL OF THE NEW TOPICS. ==================== Version 3.10 Build 1 - Several bug fixes. - ...

    Debugging with GDB --2007年

    Table of Contents Summary of GDB . . . . . . . . ....Free software ....Contributors to GDB ....A Sample GDB Session ....Loading the Executable ....Setting Display width....Setting Breakpoints ....Running the executable ...

    曲线拟合工具CurveExpert 1.0

    data window's edit control if it was active, resulting in one point not being scaled or translated. Fixed. + A constant starting with a decimal (eg, .25) caused CurveExpert to bomb (when defining ...

    Senfore_DragDrop_v4.1

    readme.txt file which briefly describes what the demo does and what features it uses. The demos should be run in the order in which they are listed in the supplied project group. Even if you have ...

Global site tag (gtag.js) - Google Analytics