This page is no longer maintained — Please continue to the home page at www.scala-lang.org

scala.ref

No replies
Grand, Mark D.
Joined: 2009-12-24,
User offline. Last seen 42 years 45 weeks ago.

I have enhanced the scala.ref package. I am planning to contribute this enhanced version of scala.ref to the scala codebase.  Before I do this, I am submitting the enhanced version of this package to this mailing list in hopes of getting feedback.

 

There are two enhancements that I have made to scala.ref.  The first is that I have added scaladoc comments for all of the classes and methods.

The more important enhancement I made is the one that motivated me.  In the underlying java library, when the garbage collector decides that the object referenced by a Reference object is not needed and the Reference object is associated with a ReferenceQueue object then the Reference object is added to the ReferenceQueue  (enqueued).  Application code can then notice the Reference object in the ReferenceQueue and perform appropriate cleanup.

Doing appropriate cleanup involves knowing what object the Reference object referenced before the garbage collector enqueued the Reference object.  However, after the garbage collector has enqueued a Reference object it is not possible to find out what object the Reference object referenced by calling its get method.

The usual way to solve this problem in Java is the create a subclass of the appropriate Reference subclass and add a property the provides a useful clue about what the Reference object referenced.  This is not possible using the current scala.ref library.  No provision is made for this.  Extending the Scala classes will not help since it is the underlying java Reference object and not the Scala Reference object that is added to the ReferenceQueue.

My enhanced version of scala.ref solves this problem by extending the appropriate Java Reference subclass with a Scala trait that contains the declaration
   var clue:Option[AnyRef]

The value for the underlying clue property is passed into the constructor for each concrete Reference subclass.  All Reference classes inherit a clue method from Reference.

 

I have attached a .jar file containing the enhanced scala.ref and hope that some of you will care to take the time to give me feedback.


This e-mail message (including any attachments) is for the sole use of
the intended recipient(s) and may contain confidential and privileged
information. If the reader of this message is not the intended
recipient, you are hereby notified that any dissemination, distribution
or copying of this message (including any attachments) is strictly
prohibited.

If you have received this message in error, please contact
the sender by reply e-mail message and destroy all copies of the
original message (including attachments).

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland