Posts Tagged ‘finalize’
Open Source Announcement: CleanSweep March 26, 2013 | 10:22 am

I just knocked out a generic implementation of a sweeper that leverages Java’s concurrency structures to provide a very pluggable background replacement for finalize(), which we all know is evil. It also works well for caching. You can find it over on GitHub under the name RobertFischer/CleanSweep. Instructions on its use are there, but it basically looks like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import com.smokejumperit.cleanSweep.Sweeper;
 
/* [...] */
 
    final Sweeper sweeper = new Sweeper();
 
/* [...] */
 
    Object it = new Object();
    sweeper.onGC(it, new Runnable() {
      public void run() {
        System.out.println("onGC action run!");
      }
    });