A DESCRIPTION OF THE REQUEST :
Currently there is no simple way to claim global\shared resources consumed by an instance of a object. There is no guarantee that a finalize will ever execute in an object.
JUSTIFICATION :
This enhancement will allow developers to optimize desktop applications meanwhile taking advantages of the built in Garbage Collection
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Add following methods to the java.lang.System class
//Returns true only and only if the given ref points to object thats not been
//finalized and can be finalized
public boolean isGarbage(WeakReference ref) {
}
//Call finalize on the object the given ref points to only and only if isGarbage()
//returns true for the given reference. Other wise NoTGrabgeException is //thrown. This method does not gurantee that memory heap used by the object //ref points to, is reclaimed.
public void finalizeRef(WeakReference ref) throws NotGarbageException {
}
---------- BEGIN SOURCE ----------
Not the best way to do this just proving a point
public class ConnectionPool{
private static WeekReference connectionRef_;
private static Connection connectionSingleton_;
public static Connection get(){
// blah blah
}
private static void autoCloseConn(){
connectionSingleton_=null;
if(System.isGarbage(connectionRef_))
System.finalizeRef(connectionRef_);
}
}
public class ConnectionConsumer{
private void consume(){
Connection conn =null;
try{
conn = ConnectionPool.get();
//blah blah
}
finaly{
WeekRef ref =conn;
conn =null;
if(System.isGarbage(ref))
System.finalizeRef(ref);
}
}
}
---------- END SOURCE ----------
Currently there is no simple way to claim global\shared resources consumed by an instance of a object. There is no guarantee that a finalize will ever execute in an object.
JUSTIFICATION :
This enhancement will allow developers to optimize desktop applications meanwhile taking advantages of the built in Garbage Collection
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Add following methods to the java.lang.System class
//Returns true only and only if the given ref points to object thats not been
//finalized and can be finalized
public boolean isGarbage(WeakReference ref) {
}
//Call finalize on the object the given ref points to only and only if isGarbage()
//returns true for the given reference. Other wise NoTGrabgeException is //thrown. This method does not gurantee that memory heap used by the object //ref points to, is reclaimed.
public void finalizeRef(WeakReference ref) throws NotGarbageException {
}
---------- BEGIN SOURCE ----------
Not the best way to do this just proving a point
public class ConnectionPool{
private static WeekReference connectionRef_;
private static Connection connectionSingleton_;
public static Connection get(){
// blah blah
}
private static void autoCloseConn(){
connectionSingleton_=null;
if(System.isGarbage(connectionRef_))
System.finalizeRef(connectionRef_);
}
}
public class ConnectionConsumer{
private void consume(){
Connection conn =null;
try{
conn = ConnectionPool.get();
//blah blah
}
finaly{
WeekRef ref =conn;
conn =null;
if(System.isGarbage(ref))
System.finalizeRef(ref);
}
}
}
---------- END SOURCE ----------
- relates to
-
JDK-5059757 RFE: forced garbage collect of an object for classloader issues
-
- Open
-