Fourth back to Java: Java memory allocation and garbage collection mechanism: white-headed and new

Source: Internet
Author: User

I have written a lot of small programs, but I still know little about memory allocation. I learned Java, and I have some basic knowledge about it, so I can write it out and forget it.

For some primitive types, we call them value types. Normally, the allocated memory space is in the stack, while for the types created through new, they are in the heap. It is better to use code to explain.

 

Public String cursor; Public int teachage; visitor = new visitor ();

For the above Code, cursor and teachage are in the stack, visitor is in the stack, and the visitor object is in the heap. I am confused myself, sorry. Lazy, don't want to draw a picture, that is, the visitor in the stack points to the memory allocated for the visitor in the heap. This sentence is clear.

Memory Allocation is still a problem for me. I also need to learn the garbage collection mechanism in Java. Currently, I know the garbage collection mechanism as follows: Java has a garbage collector, periodically scan the "Empty memory", that is, the memory with no pointer pointing to, and then release it. It's not enough to simply understand it! Not enough...

 

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.