: 33From the running results of the program can be found, the content of two objects output, in fact, the so-called reference Pass, is the use of a heap of memory space to a plurality of stack memory space, each stack of memory space can modify the contents of the heap memory space, the program's
Original addressObjective
See a question on Segmentfault: Java has a well-developed GC mechanism, so whether there will be a memory leak in Java, and can give a case of a memory leak. This problem view gives a complete answer to this question.
Introduction to garbage collection mechanism
Dur
same is true for deleting objects centrally. It causes a sudden emergence of a large number of garbage objects, the inevitable reduction of free space, thereby greatly increasing the next time to create a new object to force the main GC opportunity.
5, Java even if there is a GC will also occur memory leaks. An example is provided. 1. The use of static collect
; Reentrantlock Lock=NewReentrantlock (); Public voidwriter () {lock.lock (); //Get lock Try{a++; } finally{lock.unlock (); //Release Lock }} Public voidReader () {lock.lock (); //Get lock Try { inti =A; ...... } finally{lock.unlock (); //Release Lock }}}In Reentrantlock, call the Lock () method to get the lock, and call the Unlock () method to release the lock.The implementation of Reentrantlock relies on the Java Synchronizer Fram
we do not need, not in use of goods, these items crowding out the space we need,And let's have the idea of discarding it to free up more space.There are two very important benchmarks in this understanding of rubbish, one is the object and the other is space.1. Heap Memory:In Java, the object corresponds to "objects", and space is "Java Heap
entered into a program module You must know the size of the data area required by the program module to allocate memory for it. As with the stack we are familiar with in the data structure, the stack storage allocation is distributed according to the principle of advanced post-out.Static storage allocation requires that the storage requirements of all variables be known at compile time, and that the stack storage allocation requires that all storage
compilation period.
Direct MemoryDirect memory is not part of the data area when the virtual machine is running, nor is the memory area defined in the Java VM Specification, which is an area of memory outside the JVM, which can also cause outofmemoryerror exceptions.
JVM parameters-XSS (stackspace) stack spac
Recently found two Java virtual machine aspects of the book, looked at the Java Automatic Memory management chapters, write the same, in this summary, mainly three aspects: Memory partition, memory allocation, memory recycling.
pool.The OutOfMemoryError exception is thrown when the method area does not meet the memory allocation requirements.5, the local method stack (Native methods stack)The local method stack is very similar to the virtual machine stack, but the difference is that the virtual machine stack executes Java methods (that is, bytecode) services for the virtual machine, while the local method stack serves the native
been confirmed by the various literal constants.Object creation Process:When the virtual opportunity goes to a new command, go to the constant pool to find the symbol reference for the class, and then check to see if the symbol reference represents a class that has already been loaded, initialized, and, if not, Just go find the. Class execution class loading process, after the class load completes, the virtual machine allocates the memory for the obj
)20.152302906758376% usedPS Perm GenerationCapacity = 85983232 (82.0MB)used = 60770232 (57.95500946044922MB)Free = 25213000 (24.04499053955078MB)70.67684080542588% used
And then use PS to see:
The code is as follows
Copy Code
[Lex@chou ~]$ ps-p 837-o Vsz,rssVSZ RSS7794992 3047320
About here a few generation online data a lot of not elaborate, here calculate sum can be learned that the former total to th
(411.06592559814453 MB)20.152302906758376% usedPS Perm GenerationCapacity = 85983232 (82.0 MB)Used = 60770232 (57.95500946044922 MB)Free = 25213000 (24.04499053955078 MB)70.67684080542588% used and then use ps to look at it:[Lex @ chou ~] $ Ps-p 837-o vsz, rssVSZ RSS7794992 3047320 I will not elaborate on the several generation online materials here. Here, we can calculate the sum and we can see that the former has allocated a total of 64 4 MB of
Jstat-gcutil PID 10000
Lsof-p PID
Lsof-p PID | Wc-l
LS-AL/PROC/PID/FD #直接打印出当前此process all open files
jmap-histo:live pid > Info.log
Jmap-dump:live,file=mydumpfile PID
Jhat Mydumpfile
http://ip:7000 page directly to the bottom, you can see the number of instances cited ranking, where memory leaks.
Lsof-p 26674 ls-al/proc/pid/fdThere are large quantities of open anon_inode:[eventpoll] and pipe, if more than 100 eventpoll,Typically, too many handlert
pool, for the compilation period generated by a variety of literal and symbolic references, which will be loaded in the class load into the method area of the run constant pool. ), and check to see if the class represented by the symbol reference has been loaded, parsed, and initialized. If not, you must first perform the appropriate class loading process.Ii. allocating memory for new objectsThe memory siz
In Java, memory is managed by a virtual machine, and unlike C + + you need to write the appropriate Delete/free method for each object, and it is not easy to have memory leaks and memory overflow problems.The Java Virtual machine
; Reentrantlock Lock=NewReentrantlock (); Public voidwriter () {lock.lock (); //Get lock Try{a++; } finally{lock.unlock (); //Release Lock }} Public voidReader () {lock.lock (); //Get lock Try { inti =A; ...... } finally{lock.unlock (); //Release Lock }}}In Reentrantlock, call the Lock () method to get the lock, and call the Unlock () method to release the lock.The implementation of Reentrantlock relies on the Java Synchronizer Fram
, the creation of objects, in the heap to open memory when the memory is allocated? 2. How are object references found in our object instances in the heap? Through these two questions to deepen our understanding.1. How do I allocate memory when I create an object and open up memory in the heap?Two ways: pointer collisi
Haven't written a blog for a long time, deeply ashamed, today talk about Java memory managementBrief introductionOne of the advantages of Java compared to traditional languages (c,c++) is its ability to automatically manage memory, stripping developers of managing memory tas
faster:Run the program with the following command, and be careful to compile the. Java source file into a. class bytecode file with the Javac command first. Java-xms10m-xmx10m-xx:-usegcoverheadlimit Oomtest2. Memory Overflowmemory overflow means that when we create a new strength object, the instance object takes up more mem
Test method: At the command line with Java-xmxxxxxm-version, such as: java-xmx1024m-version command to test, and then gradually increase the value of XXXX, if performed normally indicates that the specified memory size is available, otherwise the error message will be printed.
Heap and non-heap (non-heap) memoryAccording to the official statement, "
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.