Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the memory Management of Java Code

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about how to understand the memory management of Java code. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.

The editor introduces the memory management of Java code through several aspects.

Some of the code, GC simply can not be recycled, directly hang up the system. GC is a program, not intelligent. It only collects what he thinks, not what you think.

GC garbage collection:

Grabage Collection believes that anyone who has studied JAVA knows what this means. But how does he work?

First of all, when JVM manages memory, the management of variables is always divided into new objects and old objects. The new object is the object produced by the developer new, but because of its short life cycle, the memory occupied by it is not released immediately, but is marked as an old object. At this time, the object will still exist for a period of time. It is then up to JVM to decide whether he is a garbage object and recycle it.

So we can know that junk memory is not released immediately after running out, so it will cause the phenomenon that memory is not released in time, thus reducing the use of memory. And when the program is huge. This phenomenon is more obvious, and the work of GC also needs to consume resources. Therefore, there will be a waste of memory.

Talk about memory recovery in the life cycle of objects in JVM:

The life cycle of an object is generally divided into seven stages: creation phase, application phase, invisible phase, unreachable phase, collectable phase, terminal phase, and release phase.

Creation phase: first of all, take a look at the following two pieces of code:

Test1:

For (int item0; I

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report