Recent Entries »

Java PhantomReferences: A better choice than finalize()

We’ve talked about soft and weak references, and how they differ from strong references. But what about phantom references? What are they useful for?

Starting with Java 9, the intended usage of PhantomReference objects is to replace any usage of Object.finalize() (which was deprecated in Java 9), in order to allow for this sort of object clean-up code to be run in a more predicable manner (as designated by the programmer), rather than subject to the constraints/implementation details of the garbage collector.

Continued

Java and Soft References

In a previous post, I described what weak references were and how the JVM interacted with them and how they contrasted with strong references. In summary, a strong reference is what we typically think of as a reference in Java; that is, when we instantiate an object and assign its reference to a variable, that is a strong reference. Obviously, these objects will not be cleared by the garbage collector (GC) until the reference is removed.

By contrast, a weak reference doesn’t prevent the garbage collector from clearing the referred object. That is, if the only references that remain to an object are weak references, that object will be treated as if there are no strong references to it, and thus it will be cleared by the GC on its next run. Weak references are implemented mainly by the WeakReference “wrapper” and WeakHashMap, the latter of which only maintains weak references to the keys, so that once the keys are inaccessible (i.e. no strong references exist), the WeakHashMap will automatically drop/remove the corresponding entries, which can also make the value objects eligible for GC so as long as there are no other references to them.

But how do these references contrast with a soft reference?

Continued

Analysis of the 2011-2015 Boston Marathon results

I recently analyzed the 2011-2015 Boston Marathon results. You can see the results in this GitHub Repo, or go straight to the IPython/Jupyter Notebook for the details.

Boston’s getting competitive

One of the more interesting observations is that with the tighter qualifying standards the race is much more competitive. Runners have apparently responded by stepping up their game, or perhaps, the race is now limited to faster runners.

The combination of a -5 minute adjustment across the board combined with the “fastest get in first” rule has created a much more competitive environment. This can be seen by comparing the distribution of finishing times for the M18-39 age group from 2011 (before the changes) to 2015 (the most recent year). (Both years generally were “fast”, as measured the mean and median finishing times)

boston-2011

boston-2015

You can see that the mode (most frequent bin) has been pushed from sub-3:10 to sub-3:00. This is very impressive for such a large race.

Check out the full results for more details!