Accessibility issues for objects in Java

Source: Internet
Author: User
Tags variable scope
(Note: This article refers to the knowledge purely for technical exchange, without permission not reproduced privately)
There is also a memory leak in Java, because the object is useless but can be reached.
This subdivision is subdivided down to a total of three
1. Not available ------> The GC will help us recycle it, and C + + will not
2. not available up to ------> There is a memory leak in this situation
3. usable up to ------> normal use

1. Not available unreachable is our variable scope ended, not available
2. Cannot be used to reach, that is, we ourselves did not object to it,
As an example:
In this example, we iterate over the object and put the requested object into a vector, and if we just release the reference itself, then the vector still references the object, so the object is not recyclable to the GC. Therefore, if the object has to be removed from the vector after it has been added to the vector, the simplest way is to set the vector object to null
Vector v=new Vector (10);
for (int i=1;i<100; i++)
{
Object O=new object ();
V.add (o);
O=null;



At this time these objects are not available to the object, the GC will not help us clean up, there is a memory leak
3. Can not be used to do the introduction

Accessibility issues for objects in Java

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.