Add RestoringWeakReference #1357

Closed
wants to merge 2 commits into from

3 participants

@Shadowfiend
Lift Web Framework member

RestoringWeakReference contains a scala.ref.WeakReference that,
after it has been nulled out, uses a restorer function to restore
the value. This can be used for data that can afford to be evicted
by the garbage collector, but will be needed later. One good example
is Lift form callbacks, which may need the value of an object, but
where you don't necessarily want to be retaining the object
indefinitely while someone is on a page in the face of GC contention.

Examples are in the doc header.

@Shadowfiend Shadowfiend Add RestoringWeakReference to utils.
RestoringWeakReference contains a scala.ref.WeakReference that, after it
has been nulled out, uses a restorer function to restore the value.
This can be used for data that can afford to be evicted by the garbage
collector, but will be needed later. One good example is Lift form
callbacks, which may need the value of an object, but where you don't
necessarily want to be retaining the object indefinitely while someone
is on a page in the face of GC contention.
5833892
@Shadowfiend
Lift Web Framework member

We've used this class to great effect at OpenStudy to manage GC overhead from closure object retention.

@fmpwizard
Lift Web Framework member

Womp womp :p

@fmpwizard
Lift Web Framework member

Thanks for adding this, any chance to get a spec test with the pull req?

Looks nice.
It might be more in line with scala conventions to rename value to apply. Then you would write ref() instead of ref.value.

P.S. Would you you mind to fix the indentation?
Thanks.

Lift Web Framework member

Wow. No idea what happened to the indentation there. I'll definitely fix that.

As for apply vs value… Let me ponder that one for a bit.

Lift Web Framework member

Indeed, looks like WeakReference uses apply, no reason why we shouldn't do the same. Pushed that change to master.

@Shadowfiend Shadowfiend was assigned Nov 9, 2012
@Shadowfiend
Lift Web Framework member

So, I'm not sure that's the greatest idea, as I don't know what effect it'll have on the test suite. The only real way to test something like this is to force a WeakReference's eviction. And the only semi-reliable way to do that (that I've found) is to basically create objects until you get an OutOfMemory exception, which you then catch, and allow those objects to go out of scope after the try/catch. It's a bit of a pain, definitely a hack, and may or may not hose the rest of the suite when it runs.

@fmpwizard
Lift Web Framework member

yes, I thought that adding a spec test for it would prove a challenge( well, this is more like, it will messed with all the other tests), so I guess it is ok not to have a test here, we do have plenty of scaladoc explaining it, so that's great, thanks!

@fmpwizard
Lift Web Framework member

rebased to master

@fmpwizard fmpwizard closed this Nov 10, 2012
@Shadowfiend Shadowfiend deleted the asc_issue_1357 branch Mar 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment