Java local variables

Source: Internet
Author: User

Local variable

 

The life cycle of a local variable depends on the time when the method is called and the call is terminated.

1. When a Java Virtual Machine (specifically, a thread in the Java Virtual Machine) calls a method, it allocates memory for the local variables in the method.

 

2. When the Java Virtual Machine (specifically, a thread in the Java Virtual Machine) ends calling a method, the lifecycle of local variables in the method ends.

 

 

Therefore, the following code is not necessary in general:

Public class sample {

Public void test (){

Person P = new person ();

P. Talk ();

P = NULL; // No, because the life cycle of the local variable ends after the method call ends.

}

}

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.