(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